diff options
author | parsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-06-26 00:09:49 +0000 |
---|---|---|
committer | parsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-06-26 00:09:49 +0000 |
commit | be1044516643d17339fa29a028a5cc0148e0df29 (patch) | |
tree | a177e23b0c5a78715e74846873333c4be2524449 | |
parent | 41e83ee103bea2eac259d5bc08aabc1fe7389671 (diff) | |
download | ATCD-be1044516643d17339fa29a028a5cc0148e0df29.tar.gz |
ChangeLogTag: Wed Jun 25 19:01:33 2003 Jeff Parsons <j.parsons@vanderbilt.edu>
31 files changed, 706 insertions, 178 deletions
diff --git a/TAO/ChangeLog_ref b/TAO/ChangeLog_ref index 1923f6550de..22736e14c95 100644 --- a/TAO/ChangeLog_ref +++ b/TAO/ChangeLog_ref @@ -1,3 +1,51 @@ +Wed Jun 25 19:01:33 2003 Jeff Parsons <j.parsons@vanderbilt.edu> + + * TAO_IDL/be_include/be_visitor_traits.h: + * TAO_IDL/be/be_visitor_traits.cpp: + + New files, a visitor that generates specialized traits template + classes in a separate pass over the AST. + + * TAO_IDL/Makefile.BE: + * TAO_IDL/TAO_IDL_BE.bor: + * TAO_IDL/TAO_IDL_BE_DLL.dsp: + * TAO_IDL/be/be_argument.cpp: + * TAO_IDL/be/be_decl.cpp: + * TAO_IDL/be/be_interface.cpp: + * TAO_IDL/be/be_interface_fwd.cpp: + * TAO_IDL/be/be_operation.cpp: + * TAO_IDL/be/be_type.cpp: + * TAO_IDL/be/be_valuetype.cpp: + * TAO_IDL/be/be_visitor_root.cpp: + * TAO_IDL/be/be_visitor_interface/interface_cs.cpp: + * TAO_IDL/be/be_visitor_root/root.cpp: + * TAO_IDL/be/be_visitor_sequence/sequence_ch.cpp: + * TAO_IDL/be/be_visitor_sequence/sequence_cs.cpp: + * TAO_IDL/be/be_visitor_valuetype/valuetype_cs.cpp: + * TAO_IDL/be_include/be_decl.h: + * TAO_IDL/be_include/be_interface_fwd.h: + * TAO_IDL/be_include/be_type.h: + * tao/Objref_VarOut_T.cpp: + * tao/Objref_VarOut_T.h: + * tao/PolicyC.cpp: + * tao/Policy_ForwardC.h: + * tao/Sequence_T.cpp: + * tao/Sequence_T.h: + * tao/Valuetype/Sequence_T.inl: + * tao/Valuetype/Value_VarOut_T.cpp: + * tao/Valuetype/Value_VarOut_T.h: + + Partial support for traits code generation, along with + corresponding changes to ORB code, some of it temporary + until the hand-crafted files can be regenerated. These + changes add code generation for interface and valuetype + traits, and modify sequence code to use some of these + traits. + + Also removed the _upcast and _downcast methods from + bounded and unbounded versions of object sequences. + These methods never seem to be called. + Wed Jun 25 08:36:06 2003 Jeff Parsons <j.parsons@vanderbilt.edu> * tao/Sequence_T.cpp: diff --git a/TAO/TAO_IDL/Makefile.BE b/TAO/TAO_IDL/Makefile.BE index 85dd6090ed9..4726e363845 100644 --- a/TAO/TAO_IDL/Makefile.BE +++ b/TAO/TAO_IDL/Makefile.BE @@ -98,6 +98,7 @@ FILES = be/be_array \ be/be_visitor_sequence \ be/be_visitor_structure \ be/be_visitor_structure_fwd \ + be/be_visitor_traits \ be/be_visitor_typecode \ be/be_visitor_typedef \ be/be_visitor_union \ diff --git a/TAO/TAO_IDL/TAO_IDL_BE.bor b/TAO/TAO_IDL/TAO_IDL_BE.bor index abeeb785cff..10e7b118a67 100644 --- a/TAO/TAO_IDL/TAO_IDL_BE.bor +++ b/TAO/TAO_IDL/TAO_IDL_BE.bor @@ -78,6 +78,7 @@ OBJFILES = \ $(OBJDIR)\be_visitor_sequence.obj \ $(OBJDIR)\be_visitor_structure.obj \ $(OBJDIR)\be_visitor_structure_fwd.obj \ + $(OBJDIR)\be_visitor_traits.obj \ $(OBJDIR)\be_visitor_typecode.obj \ $(OBJDIR)\be_visitor_typedef.obj \ $(OBJDIR)\be_visitor_union.obj \ diff --git a/TAO/TAO_IDL/TAO_IDL_BE_DLL.dsp b/TAO/TAO_IDL/TAO_IDL_BE_DLL.dsp index f7dd64a26d0..26936cfbc55 100644 --- a/TAO/TAO_IDL/TAO_IDL_BE_DLL.dsp +++ b/TAO/TAO_IDL/TAO_IDL_BE_DLL.dsp @@ -398,6 +398,10 @@ SOURCE=.\be\be_visitor_structure_fwd.cpp # End Source File
# Begin Source File
+SOURCE=.\be\be_visitor_traits.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\be\be_visitor_typecode.cpp
# End Source File
# Begin Source File
@@ -722,6 +726,10 @@ SOURCE=.\be_include\be_visitor_structure_fwd.h # End Source File
# Begin Source File
+SOURCE=.\be_include\be_visitor_traits.h
+# End Source File
+# Begin Source File
+
SOURCE=.\be_include\be_visitor_typecode.h
# End Source File
# Begin Source File
diff --git a/TAO/TAO_IDL/be/be_argument.cpp b/TAO/TAO_IDL/be/be_argument.cpp index 0a4fc22ffc5..fdb3e16529e 100644 --- a/TAO/TAO_IDL/be/be_argument.cpp +++ b/TAO/TAO_IDL/be/be_argument.cpp @@ -20,6 +20,7 @@ // ============================================================================ #include "be_argument.h" +#include "be_type.h" #include "be_visitor.h" ACE_RCSID (be, @@ -42,6 +43,8 @@ be_argument::be_argument (AST_Argument::Direction d, AST_Decl (AST_Decl::NT_argument, n) { + be_type *bt = be_type::narrow_from_decl (ft); + bt->seen_in_operation (I_TRUE); } diff --git a/TAO/TAO_IDL/be/be_decl.cpp b/TAO/TAO_IDL/be/be_decl.cpp index 702456a3547..08c9755fed4 100644 --- a/TAO/TAO_IDL/be/be_decl.cpp +++ b/TAO/TAO_IDL/be/be_decl.cpp @@ -60,7 +60,8 @@ be_decl::be_decl (void) cli_hdr_cdr_op_gen_ (I_FALSE), cli_stub_cdr_op_gen_ (I_FALSE), cli_inline_cdr_op_gen_ (I_FALSE), - cli_inline_cdr_decl_gen_ (I_FALSE) + cli_inline_cdr_decl_gen_ (I_FALSE), + cli_traits_gen_ (I_FALSE) { } @@ -82,7 +83,8 @@ be_decl::be_decl (AST_Decl::NodeType type, cli_hdr_cdr_op_gen_ (I_FALSE), cli_stub_cdr_op_gen_ (I_FALSE), cli_inline_cdr_op_gen_ (I_FALSE), - cli_inline_cdr_decl_gen_ (I_FALSE) + cli_inline_cdr_decl_gen_ (I_FALSE), + cli_traits_gen_ (I_FALSE) { } @@ -317,6 +319,12 @@ be_decl::cli_inline_cdr_decl_gen (void) } idl_bool +be_decl::cli_traits_gen (void) +{ + return this->cli_traits_gen_; +} + +idl_bool be_decl::cli_inline_gen (void) { return this->cli_inline_gen_; @@ -408,6 +416,12 @@ be_decl::cli_inline_gen (idl_bool val) } void +be_decl::cli_traits_gen (idl_bool val) +{ + this->cli_traits_gen_ = val; +} + +void be_decl::srv_hdr_gen (idl_bool val) { this->srv_hdr_gen_ = val; diff --git a/TAO/TAO_IDL/be/be_interface.cpp b/TAO/TAO_IDL/be/be_interface.cpp index a6ac59e7bc4..0055c558d5a 100644 --- a/TAO/TAO_IDL/be/be_interface.cpp +++ b/TAO/TAO_IDL/be/be_interface.cpp @@ -578,7 +578,7 @@ be_interface:: gen_var_out_seq_decls (void) // Generate the ifdefined macro for this interface. os->gen_ifdef_macro (this->flat_name (), - "odds_n_ends"); + "var_out"); *os << be_nl << be_nl << "class " << lname << ";" << be_nl diff --git a/TAO/TAO_IDL/be/be_interface_fwd.cpp b/TAO/TAO_IDL/be/be_interface_fwd.cpp index 47e871fc249..d2982782e1a 100644 --- a/TAO/TAO_IDL/be/be_interface_fwd.cpp +++ b/TAO/TAO_IDL/be/be_interface_fwd.cpp @@ -20,6 +20,7 @@ // ============================================================================ #include "be_interface_fwd.h" +#include "be_interface.h" #include "be_visitor.h" #include "ast_interface.h" @@ -50,6 +51,33 @@ be_interface_fwd::~be_interface_fwd (void) { } +void +be_interface_fwd::seq_elem_tmplinst (idl_bool val) +{ + this->be_type::seq_elem_tmplinst (val); + be_interface *fd = + be_interface::narrow_from_decl (this->full_definition ()); + fd->seq_elem_tmplinst (val); +} + +void +be_interface_fwd::seen_in_sequence (idl_bool val) +{ + this->be_type::seen_in_sequence (val); + be_interface *fd = + be_interface::narrow_from_decl (this->full_definition ()); + fd->seen_in_sequence (val); +} + +void +be_interface_fwd::seen_in_operation (idl_bool val) +{ + this->be_type::seen_in_operation (val); + be_interface *fd = + be_interface::narrow_from_decl (this->full_definition ()); + fd->seen_in_operation (val); +} + void be_interface_fwd::destroy (void) { diff --git a/TAO/TAO_IDL/be/be_operation.cpp b/TAO/TAO_IDL/be/be_operation.cpp index 100027e3577..7220d7d1d0a 100644 --- a/TAO/TAO_IDL/be/be_operation.cpp +++ b/TAO/TAO_IDL/be/be_operation.cpp @@ -53,6 +53,9 @@ be_operation::be_operation (AST_Type *rt, { ACE_NEW (this->strategy_, be_operation_default_strategy (this)); + + be_type *bt = be_type::narrow_from_decl (rt); + bt->seen_in_operation (I_TRUE); } diff --git a/TAO/TAO_IDL/be/be_type.cpp b/TAO/TAO_IDL/be/be_type.cpp index 46bf479040b..6250ebfdf1b 100644 --- a/TAO/TAO_IDL/be/be_type.cpp +++ b/TAO/TAO_IDL/be/be_type.cpp @@ -35,7 +35,9 @@ ACE_RCSID (be, be_type::be_type (void) : tc_name_ (0), common_varout_gen_ (I_FALSE), - seen_in_sequence_ (I_FALSE) + seq_elem_tmplinst_ (I_FALSE), + seen_in_sequence_ (I_FALSE), + seen_in_operation_ (I_FALSE) { } @@ -49,7 +51,9 @@ be_type::be_type (AST_Decl::NodeType nt, n), tc_name_ (0), common_varout_gen_ (I_FALSE), - seen_in_sequence_ (I_FALSE) + seq_elem_tmplinst_ (I_FALSE), + seen_in_sequence_ (I_FALSE), + seen_in_operation_ (I_FALSE) { if (n != 0) { @@ -347,6 +351,18 @@ be_type::gen_common_tmplinst (TAO_OutStream *os) } idl_bool +be_type::seq_elem_tmplinst (void) const +{ + return this->seq_elem_tmplinst_; +} + +void +be_type::seq_elem_tmplinst (idl_bool val) +{ + this->seq_elem_tmplinst_ = val; +} + +idl_bool be_type::seen_in_sequence (void) const { return this->seen_in_sequence_; @@ -358,6 +374,18 @@ be_type::seen_in_sequence (idl_bool val) this->seen_in_sequence_ = val; } +idl_bool +be_type::seen_in_operation (void) const +{ + return this->seen_in_operation_; +} + +void +be_type::seen_in_operation (idl_bool val) +{ + this->seen_in_operation_ = val; +} + AST_Decl::NodeType be_type::base_node_type (void) const { diff --git a/TAO/TAO_IDL/be/be_valuetype.cpp b/TAO/TAO_IDL/be/be_valuetype.cpp index 21d78798182..de75fd77844 100644 --- a/TAO/TAO_IDL/be/be_valuetype.cpp +++ b/TAO/TAO_IDL/be/be_valuetype.cpp @@ -286,7 +286,7 @@ be_valuetype:: gen_var_out_seq_decls (void) // Generate the ifdefined macro for this interface. os->gen_ifdef_macro (this->flat_name (), - "odds_n_ends"); + "var_out"); const char *lname = this->local_name (); diff --git a/TAO/TAO_IDL/be/be_visitor_interface/interface_cs.cpp b/TAO/TAO_IDL/be/be_visitor_interface/interface_cs.cpp index 686c2f11395..dfcbaace023 100644 --- a/TAO/TAO_IDL/be/be_visitor_interface/interface_cs.cpp +++ b/TAO/TAO_IDL/be/be_visitor_interface/interface_cs.cpp @@ -40,7 +40,7 @@ be_visitor_interface_cs::~be_visitor_interface_cs (void) int be_visitor_interface_cs::visit_interface (be_interface *node) { - if (node->cli_stub_gen () || node->imported ()) + if (node->imported () || node->cli_stub_gen ()) { return 0; } @@ -62,6 +62,52 @@ be_visitor_interface_cs::visit_interface (be_interface *node) *os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl << "// " << __FILE__ << ":" << __LINE__; + *os << be_nl << be_nl + << "// Traits specializations for " << node->name () << "."; + + *os << be_nl << be_nl + << "template<>" << be_nl + << node->name () << "_ptr" << be_nl + << "TAO::Objref_Traits<" << node->name () << ">::tao_duplicate (" + << be_idt << be_idt_nl + << node->name () << "_ptr p" << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl + << "return " << node->name () << "::_duplicate (p);" << be_uidt_nl + << "}"; + + *os << be_nl << be_nl + << "template<>" << be_nl + << "void" << be_nl + << "TAO::Objref_Traits<" << node->name () << ">::tao_release (" + << be_idt << be_idt_nl + << node->name () << "_ptr p" << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl + << "CORBA::release (p);" << be_uidt_nl + << "}"; + + *os << be_nl << be_nl + << "template<>" << be_nl + << node->name () << "_ptr" << be_nl + << "TAO::Objref_Traits<" << node->name () << ">::tao_nil (void)" + << be_nl + << "{" << be_idt_nl + << "return " << node->name () << "::_nil ();" << be_uidt_nl + << "}"; + + *os << be_nl << be_nl + << "template<>" << be_nl + << "CORBA::Boolean" << be_nl + << "TAO::Objref_Traits<" << node->name () << ">::tao_marshal (" + << be_idt << be_idt_nl + << node->name () << "_ptr p," << be_nl + << "TAO_OutputCDR & cdr" << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl + << "return p->marshal (cdr);" << be_uidt_nl + << "}"; + // Initialize the static narrrowing helper variable. *os << be_nl << be_nl << "int " << node->full_name () << "::_tao_class_id = 0;"; @@ -199,7 +245,7 @@ be_visitor_interface_cs::visit_interface (be_interface *node) // Interceptor classes. The interceptors helper classes must be // defined before the interface operations because they are used in - // the implementation of said operations. + // the implementation of these operations. ctx.state (TAO_CodeGen::TAO_INTERFACE_INTERCEPTORS_CS); be_visitor_interface_interceptors_cs ii_visitor (&ctx); diff --git a/TAO/TAO_IDL/be/be_visitor_root.cpp b/TAO/TAO_IDL/be/be_visitor_root.cpp index aed1dba18d4..569924f5b47 100644 --- a/TAO/TAO_IDL/be/be_visitor_root.cpp +++ b/TAO/TAO_IDL/be/be_visitor_root.cpp @@ -57,6 +57,7 @@ #include "be_visitor_component.h" #include "be_visitor_component_fwd.h" #include "be_visitor_home.h" +#include "be_visitor_traits.h" #include "be_visitor_context.h" #include "be_visitor_root/root.cpp" diff --git a/TAO/TAO_IDL/be/be_visitor_root/root.cpp b/TAO/TAO_IDL/be/be_visitor_root/root.cpp index e4edbad1c37..800e5cd83e5 100644 --- a/TAO/TAO_IDL/be/be_visitor_root/root.cpp +++ b/TAO/TAO_IDL/be/be_visitor_root/root.cpp @@ -201,6 +201,24 @@ int be_visitor_root::visit_root (be_root *node) } } + status = 0; + ctx = *this->ctx_; + + if (this->ctx_->state () == TAO_CodeGen::TAO_ROOT_CH) + { + be_visitor_traits visitor (&ctx); + status = node->accept (&visitor); + + if (status == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_root::" + "visit_root - " + "failed to generate traits\n"), + -1); + } + } + // The next thing we need to do is make one more pass thru the entire tree // and generate code for all the <<= and >>= operators for all the // user-defined types. diff --git a/TAO/TAO_IDL/be/be_visitor_sequence/sequence_ch.cpp b/TAO/TAO_IDL/be/be_visitor_sequence/sequence_ch.cpp index 7ccf69c22ed..e1c6780ea2d 100644 --- a/TAO/TAO_IDL/be/be_visitor_sequence/sequence_ch.cpp +++ b/TAO/TAO_IDL/be/be_visitor_sequence/sequence_ch.cpp @@ -71,6 +71,7 @@ int be_visitor_sequence_ch::visit_sequence (be_sequence *node) -1); } + bt->seen_in_sequence (I_TRUE); AST_Decl::NodeType nt = bt->node_type (); // If our base type is an anonymouse sequence, we must create a name diff --git a/TAO/TAO_IDL/be/be_visitor_sequence/sequence_cs.cpp b/TAO/TAO_IDL/be/be_visitor_sequence/sequence_cs.cpp index 6ff757078b2..1ad8a506f1a 100644 --- a/TAO/TAO_IDL/be/be_visitor_sequence/sequence_cs.cpp +++ b/TAO/TAO_IDL/be/be_visitor_sequence/sequence_cs.cpp @@ -39,13 +39,7 @@ int be_visitor_sequence_cs::visit_sequence (be_sequence *node) { be_type *bt = be_type::narrow_from_decl (node->base_type ()); - if (node->imported ()) - { - bt->seen_in_sequence (I_TRUE); - return 0; - } - - if (node->cli_stub_gen ()) + if (node->imported () || node->cli_stub_gen ()) { return 0; } @@ -200,10 +194,11 @@ int be_visitor_sequence_cs::visit_sequence (be_sequence *node) << "}"; } - if (!bt->seen_in_sequence ()) + if (!bt->seq_elem_tmplinst ()) { // This is a no-op unless our element is a managed type. this->gen_managed_type_tmplinst (node, bt); + bt->seq_elem_tmplinst (I_TRUE); } if (this->ctx_->tdef () != 0) @@ -233,7 +228,6 @@ int be_visitor_sequence_cs::visit_sequence (be_sequence *node) os->gen_endif (); - bt->seen_in_sequence (I_TRUE); node->cli_stub_gen (I_TRUE); return 0; } diff --git a/TAO/TAO_IDL/be/be_visitor_traits.cpp b/TAO/TAO_IDL/be/be_visitor_traits.cpp new file mode 100644 index 00000000000..7e44beb5c4e --- /dev/null +++ b/TAO/TAO_IDL/be/be_visitor_traits.cpp @@ -0,0 +1,332 @@ +//============================================================================= +/** +* @file be_visitor_traits.cpp +* +* $Id$ +* +* This visitor generates template specializations for traits of various +* kinds for IDL declarations. These specialized template classes are then +* used in other template classes in the ORB. +* +* @author Jeff Parsons <j.parsons@vanderbilt.edu> +*/ +//============================================================================= + +#include "be_visitor_traits.h" +#include "be_visitor_context.h" +#include "be_root.h" +#include "be_module.h" +#include "be_interface.h" +#include "be_valuetype.h" +#include "be_interface_fwd.h" +#include "be_valuetype_fwd.h" +#include "be_eventtype.h" +#include "be_eventtype_fwd.h" +#include "be_array.h" +#include "be_enum.h" +#include "be_structure.h" +#include "be_union.h" +#include "be_typedef.h" +#include "be_helper.h" +#include "be_extern.h" +#include "utl_identifier.h" + +be_visitor_traits::be_visitor_traits (be_visitor_context *ctx) + : be_visitor_scope (ctx) +{ +} + +be_visitor_traits::~be_visitor_traits (void) +{ +} + +int +be_visitor_traits::visit_root (be_root *node) +{ + TAO_OutStream *os = this->ctx_->stream (); + + *os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl + << "// " << __FILE__ << ":" << __LINE__; + + *os << be_nl << be_nl + << "// Traits specializations." << be_nl + << "namespace TAO" << be_nl + << "{" << be_idt; + + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_traits::" + "visit_root - visit scope failed\n"), + -1); + } + + *os << be_uidt_nl + << "};"; + + return 0; +} + +int +be_visitor_traits::visit_module (be_module *node) +{ + if (!node->imported () && this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_traits::" + "visit_module - visit scope failed\n"), + -1); + } + + return 0; +} + +int +be_visitor_traits::visit_interface (be_interface *node) +{ + if (node->cli_traits_gen ()) + { + return 0; + } + + TAO_OutStream *os = this->ctx_->stream (); + + *os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl + << "// " << __FILE__ << ":" << __LINE__; + + os->gen_ifdef_macro (node->flat_name (), "traits"); + + // Since the three blocks below generate specialized (i.e., non-template) + // classes, we don't want to generate them unless it's necessary - thus + // the logic surrounding each one. + + // This is used by the _var and _out classes, so it should always be + // generated in the main file. + if (!node->imported ()) + { + *os << be_nl << be_nl + << "template<>" << be_nl + << "struct " << be_global->stub_export_macro () << " Objref_Traits<" + << node->name () << ">" << be_nl + << "{" << be_idt_nl + << "static " << node->name () << "_ptr tao_duplicate (" + << be_idt << be_idt_nl + << node->name () << "_ptr" << be_uidt_nl + << ");" << be_uidt_nl + << "static void tao_release (" << be_idt << be_idt_nl + << node->name () << "_ptr" << be_uidt_nl + << ");" << be_uidt_nl + << "static " << node->name () << "_ptr tao_nil (void);" << be_nl + << "static CORBA::Boolean tao_marshal (" << be_idt << be_idt_nl + << node->name () << "_ptr p," << be_nl + << "TAO_OutputCDR & cdr" << be_uidt_nl + << ");" << be_uidt << be_uidt_nl + << "};"; + } + + // This should be generated even for imported nodes. The ifdef guard + // around these and the one above will protect against double declaration. + if (node->seen_in_operation ()) + { + *os << be_nl << be_nl + << "template<>" << be_nl + << "class " << be_global->stub_export_macro () << " Arg_Traits<" + << node->name () << ">" << be_idt_nl + << ": public" << be_idt << be_idt_nl + << "Object_Arg_Traits_T<" << be_idt << be_idt_nl + << node->name () << "," << be_nl + << node->name () << "_var," << be_nl + << node->name () << "_out" << be_uidt_nl + << ">" << be_uidt << be_uidt << be_uidt << be_uidt_nl + << "{" << be_nl + << "};"; + } + + os->gen_endif (); + + int status = this->visit_scope (node); + + if (status != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_traits::" + "visit_interface - visit scope failed\n"), + -1); + } + + node->cli_traits_gen (I_TRUE); + return 0; +} + +int +be_visitor_traits::visit_interface_fwd (be_interface_fwd *node) +{ + if (node->cli_traits_gen ()) + { + return 0; + } + + be_interface *fd = + be_interface::narrow_from_decl (node->full_definition ()); + + // The logic in visit_interface() should handle what gets generated + // and what doesn't. + int status = this->visit_interface (fd); + + if (status != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_traits::" + "visit_interface_fwd - code generation failed\n"), + -1); + } + + node->cli_traits_gen (I_TRUE); + return 0; +} + +int +be_visitor_traits::visit_valuetype (be_valuetype *node) +{ + if (node->imported () || node->cli_traits_gen ()) + { + return 0; + } + + TAO_OutStream *os = this->ctx_->stream (); + + *os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl + << "// " << __FILE__ << ":" << __LINE__; + + *os << be_nl << be_nl + << "template<>" << be_nl + << "struct " << be_global->stub_export_macro () << " Value_Traits<" + << node->name () << ">" << be_nl + << "{" << be_idt_nl + << "static void tao_add_ref (" << node->name () << " *);" << be_nl + << "static void tao_remove_ref (" << node->name () << " *);" + << be_uidt_nl + << "};"; + + int status = this->visit_scope (node); + + if (status != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_traits::" + "visit_valuetype - visit scope failed\n"), + -1); + } + + node->cli_traits_gen (I_TRUE); + return 0; +} + +int +be_visitor_traits::visit_valuetype_fwd (be_valuetype_fwd *node) +{ + if (node->imported () || node->cli_traits_gen ()) + { + return 0; + } + + node->cli_traits_gen (I_TRUE); + be_decl *fd = + be_decl::narrow_from_decl (node->full_definition ()); + fd->cli_traits_gen (I_TRUE); + return 0; +} + +int +be_visitor_traits::visit_eventtype (be_eventtype *node) +{ + return 0; +} + +int +be_visitor_traits::visit_eventtype_fwd (be_eventtype_fwd *node) +{ + return 0; +} + +int +be_visitor_traits::visit_array (be_array *node) +{ + if (node->imported () || node->cli_traits_gen ()) + { + return 0; + } + + node->cli_traits_gen (I_TRUE); + return 0; +} + +int +be_visitor_traits::visit_enum (be_enum *node) +{ + if (node->imported () || node->cli_traits_gen ()) + { + return 0; + } + + node->cli_traits_gen (I_TRUE); + return 0; +} + +int +be_visitor_traits::visit_structure (be_structure *node) +{ + if (node->imported () || node->cli_traits_gen ()) + { + return 0; + } + + int status = this->visit_scope (node); + + if (status != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_traits::" + "visit_structure - visit scope failed\n"), + -1); + } + + node->cli_traits_gen (I_TRUE); + return 0; +} + +int +be_visitor_traits::visit_union (be_union *node) +{ + if (node->imported () || node->cli_traits_gen ()) + { + return 0; + } + + int status = this->visit_scope (node); + + if (status != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%N:%l) be_visitor_traits::" + "visit_union - visit scope failed\n"), + -1); + } + + node->cli_traits_gen (I_TRUE); + return 0; +} + +int +be_visitor_traits::visit_typedef (be_typedef *node) +{ + if (node->imported () || node->cli_traits_gen ()) + { + return 0; + } + + node->cli_traits_gen (I_TRUE); + return 0; +} + + 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 b4559d66fcb..57bfe80f240 100644 --- a/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_cs.cpp +++ b/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_cs.cpp @@ -91,7 +91,29 @@ be_visitor_valuetype_cs::visit_valuetype (be_valuetype *node) TAO_OutStream *os = this->ctx_->stream (); *os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl - << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl; + << "// " << __FILE__ << ":" << __LINE__; + + *os << be_nl << be_nl + << "template<>" << be_nl + << "void" << be_nl + << "TAO::Value_Traits<" << node->name () << ">::tao_add_ref (" + << be_idt << be_idt_nl + << node->name () << " * p" << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl + << "CORBA::add_ref (p);" << be_uidt_nl + << "}"; + + *os << be_nl << be_nl + << "template<>" << be_nl + << "void" << be_nl + << "TAO::Value_Traits<" << node->name () << ">::tao_remove_ref (" + << be_idt << be_idt_nl + << node->name () << " * p" << be_uidt_nl + << ")" << be_uidt_nl + << "{" << be_idt_nl + << "CORBA::remove_ref (p);" << be_uidt_nl + << "}"; const char *fhname = node->fwd_helper_name (); @@ -103,7 +125,8 @@ be_visitor_valuetype_cs::visit_valuetype (be_valuetype *node) // Helper functions to allow non-defined forward declared valuetypes // access to some methods in the full definition. - *os << "void" << be_nl + *os << be_nl << be_nl + << "void" << be_nl << fhname << "_life::tao_add_ref (" << be_idt << be_idt_nl << node->full_name () << " * p" << be_uidt_nl diff --git a/TAO/TAO_IDL/be_include/be_decl.h b/TAO/TAO_IDL/be_include/be_decl.h index 217226d0147..9cf08d22907 100644 --- a/TAO/TAO_IDL/be_include/be_decl.h +++ b/TAO/TAO_IDL/be_include/be_decl.h @@ -85,6 +85,7 @@ public: idl_bool cli_stub_cdr_op_gen (void); idl_bool cli_inline_cdr_op_gen (void); idl_bool cli_inline_cdr_decl_gen (void); + idl_bool cli_traits_gen (void); // Set the flag indicating that code generation is done. void cli_hdr_gen (idl_bool); @@ -101,6 +102,7 @@ public: void cli_stub_cdr_op_gen (idl_bool); void cli_inline_cdr_op_gen (idl_bool); void cli_inline_cdr_decl_gen (idl_bool); + void cli_traits_gen (idl_bool); // Narrowing DEF_NARROW_METHODS1 (be_decl, AST_Decl); @@ -123,7 +125,7 @@ private: idl_bool cli_stub_cdr_op_gen_; idl_bool cli_inline_cdr_op_gen_; idl_bool cli_inline_cdr_decl_gen_; - + idl_bool cli_traits_gen_; }; #endif // if !defined diff --git a/TAO/TAO_IDL/be_include/be_interface_fwd.h b/TAO/TAO_IDL/be_include/be_interface_fwd.h index 34822128d63..6c2d84f7614 100644 --- a/TAO/TAO_IDL/be_include/be_interface_fwd.h +++ b/TAO/TAO_IDL/be_include/be_interface_fwd.h @@ -48,6 +48,12 @@ public: virtual ~be_interface_fwd (void); // Destructor. + virtual void seq_elem_tmplinst (idl_bool val); + virtual void seen_in_sequence (idl_bool val); + virtual void seen_in_operation (idl_bool val); + // Mutator overrides for be_type members. If we have been + // defined, we want the full definition to be set as well. + virtual void destroy (void); // Cleanup function. diff --git a/TAO/TAO_IDL/be_include/be_type.h b/TAO/TAO_IDL/be_include/be_type.h index 3eb97f4bdfc..8ce291581c8 100644 --- a/TAO/TAO_IDL/be_include/be_type.h +++ b/TAO/TAO_IDL/be_include/be_type.h @@ -66,8 +66,16 @@ public: void gen_common_tmplinst (TAO_OutStream *os); // Generate explicit template instantiations for the above. + idl_bool seq_elem_tmplinst (void) const; + virtual void seq_elem_tmplinst (idl_bool val); + // Accessors for the member. + idl_bool seen_in_sequence (void) const; - void seen_in_sequence (idl_bool val); + virtual void seen_in_sequence (idl_bool val); + // Accessors for the member. + + idl_bool seen_in_operation (void) const; + virtual void seen_in_operation (idl_bool val); // Accessors for the member. virtual AST_Decl::NodeType base_node_type (void) const; @@ -99,8 +107,15 @@ protected: idl_bool common_varout_gen_; // Have we generated our _var and _out class typedefs yet? + idl_bool seq_elem_tmplinst_; + // Have we generated an explicit template instantiation for a sequence + // with this element? + idl_bool seen_in_sequence_; - // Has this type been used as a sequence element? + // Has this declaration been used as a sequence element? + + idl_bool seen_in_operation_; + // Has this declaration been used as a return type or parameter? }; #endif // end of if !defined diff --git a/TAO/TAO_IDL/be_include/be_visitor_traits.h b/TAO/TAO_IDL/be_include/be_visitor_traits.h new file mode 100644 index 00000000000..9f61c5dd94c --- /dev/null +++ b/TAO/TAO_IDL/be_include/be_visitor_traits.h @@ -0,0 +1,60 @@ +//============================================================================= +/** +* @file be_visitor_traits.h +* +* $Id$ +* +* This visitor generates template specializations for traits of various +* kinds for IDL declarations. These specialized template classes are then +* used in other template classes in the ORB. +* +* @author Jeff Parsons <j.parsons@vanderbilt.edu> +*/ +//============================================================================= + +#ifndef TAO_BE_VISITOR_TRAITS_H +#define TAO_BE_VISITOR_TRAITS_H + +#include "be_visitor_scope.h" + +/** + * @class be_visitor_traits + * + * @brief Generates specialized template traits declarations. + */ +class be_visitor_traits : public be_visitor_scope +{ +public: + be_visitor_traits (be_visitor_context *ctx); + + virtual ~be_visitor_traits (void); + + virtual int visit_root (be_root *node); + + virtual int visit_module (be_module *node); + + virtual int visit_array (be_array *node); + + virtual int visit_enum (be_enum *node); + + virtual int visit_interface (be_interface *node); + + virtual int visit_interface_fwd (be_interface_fwd *node); + + virtual int visit_valuetype (be_valuetype *node); + + virtual int visit_valuetype_fwd (be_valuetype_fwd *node); + + virtual int visit_eventtype (be_eventtype *node); + + virtual int visit_eventtype_fwd (be_eventtype_fwd *node); + + virtual int visit_structure (be_structure *node); + + virtual int visit_union (be_union *node); + + virtual int visit_typedef (be_typedef *node); +}; + + +#endif // TAO_BE_VISITOR_TRAITS_H diff --git a/TAO/tao/Objref_VarOut_T.cpp b/TAO/tao/Objref_VarOut_T.cpp index d037bdaea94..17bb2705248 100644 --- a/TAO/tao/Objref_VarOut_T.cpp +++ b/TAO/tao/Objref_VarOut_T.cpp @@ -39,6 +39,14 @@ TAO::Objref_Traits<T>::tao_nil (void) return T::_nil (); } +template<typename T> +CORBA::Boolean +TAO::Objref_Traits<T>::tao_marshal (T * p, + TAO_OutputCDR & cdr) +{ + return p->marshal (cdr); +} + // ================================================================= template <typename T, typename T_life> diff --git a/TAO/tao/Objref_VarOut_T.h b/TAO/tao/Objref_VarOut_T.h index f0b422e956e..9f8c38af4f3 100644 --- a/TAO/tao/Objref_VarOut_T.h +++ b/TAO/tao/Objref_VarOut_T.h @@ -38,6 +38,8 @@ namespace TAO static T * tao_duplicate (T *); static void tao_release (T *); static T * tao_nil (void); + static CORBA::Boolean tao_marshal (T *, + TAO_OutputCDR &); }; }; diff --git a/TAO/tao/PolicyC.cpp b/TAO/tao/PolicyC.cpp index a5fec276946..c77a6897a3d 100644 --- a/TAO/tao/PolicyC.cpp +++ b/TAO/tao/PolicyC.cpp @@ -511,27 +511,6 @@ TAO::Objref_Traits<CORBA::Policy>::tao_nil (void) return CORBA::Policy::_nil (); } -template<> -CORBA::Policy_ptr -TAO::Object_Cast<CORBA::Policy>::tao_narrow ( - CORBA::Object *p - ACE_ENV_ARG_DECL - ) -{ - return CORBA::Policy::_narrow (p ACE_ENV_ARG_PARAMETER); -} - -template<> -CORBA::Object_ptr -TAO::Object_Cast<CORBA::Policy>::tao_upcast ( - void *src - ) -{ - CORBA::Policy_ptr *tmp = - ACE_static_cast (CORBA::Policy_ptr *, src); - return *tmp; -} - // ================================================================= // TAO_IDL - Generated from diff --git a/TAO/tao/Policy_ForwardC.h b/TAO/tao/Policy_ForwardC.h index bda110fac4e..b3b384c1331 100644 --- a/TAO/tao/Policy_ForwardC.h +++ b/TAO/tao/Policy_ForwardC.h @@ -246,22 +246,12 @@ TAO_NAMESPACE_CLOSE // module CORBA namespace TAO { template<> - struct Objref_Traits<CORBA::Policy> + struct TAO_Export Objref_Traits<CORBA::Policy> { static CORBA::Policy_ptr tao_duplicate (CORBA::Policy_ptr); static void tao_release (CORBA::Policy_ptr); static CORBA::Policy_ptr tao_nil (void); }; - - template<> - struct Object_Cast<CORBA::Policy> - { - static CORBA::Policy_ptr tao_narrow ( - CORBA::Object_ptr - ACE_ENV_ARG_DECL - ); - static CORBA::Object_ptr tao_upcast (void *); - }; }; // ========================================================== diff --git a/TAO/tao/Sequence_T.cpp b/TAO/tao/Sequence_T.cpp index 824b6042cf6..261fd3c6d3c 100644 --- a/TAO/tao/Sequence_T.cpp +++ b/TAO/tao/Sequence_T.cpp @@ -385,30 +385,6 @@ TAO_Bounded_Sequence<T,MAX>::replace (CORBA::ULong max, } // ************************************************************* -// @@@ (JP) These can be removed after we regenerate the hand-crafted files. - -template<typename T> -T * -TAO::Object_Cast<T>::tao_narrow ( - CORBA::Object *p - ACE_ENV_ARG_DECL - ) -{ - return T::_narrow (p ACE_ENV_ARG_PARAMETER); -} - -template<typename T> -CORBA::Object * -TAO::Object_Cast<T>::tao_upcast ( - void *src - ) -{ - T **tmp = - ACE_static_cast (T **, src); - return *tmp; -} - -// ************************************************************* // class TAO_Object_Manager // ************************************************************* @@ -800,32 +776,6 @@ TAO_Unbounded_Object_Sequence<T,T_var,T_life,T_cast>::_shrink_buffer ( } } -template <typename T, typename T_var, typename T_life, typename T_cast> -void -TAO_Unbounded_Object_Sequence<T,T_var,T_life,T_cast>::_downcast ( - void * target, - CORBA::Object_ptr src - ACE_ENV_ARG_DECL - ) -{ - T ** tmp = ACE_static_cast (T **, - target); - - *tmp = TAO::Object_Cast<T>::tao_narrow (src - ACE_ENV_ARG_PARAMETER); - - ACE_CHECK; -} - -template <typename T, typename T_var, typename T_life, typename T_cast> -CORBA::Object_ptr -TAO_Unbounded_Object_Sequence<T,T_var,T_life,T_cast>::_upcast ( - void * src - ) const -{ - return TAO::Object_Cast<T>::tao_upcast (src); -} - // ************************************************************* // Operations for class TAO_Bounded_Object_Sequence // ************************************************************* @@ -1038,40 +988,6 @@ TAO_Bounded_Object_Sequence<T,T_var,T_life,T_cast,MAX>::_shrink_buffer ( } } -template <typename T, - typename T_var, - typename T_life, - typename T_cast, - size_t MAX> -void -TAO_Bounded_Object_Sequence<T,T_var,T_life,T_cast,MAX>::_downcast ( - void * target, - CORBA::Object_ptr src - ACE_ENV_ARG_DECL - ) -{ - T ** tmp = ACE_static_cast (T **, - target); - - *tmp = TAO::Object_Cast<T>::tao_narrow (src - ACE_ENV_ARG_PARAMETER); - - ACE_CHECK; -} - -template <typename T, - typename T_var, - typename T_life, - typename T_cast, - size_t MAX> -CORBA::Object_ptr -TAO_Bounded_Object_Sequence<T,T_var,T_life,T_cast,MAX>::_upcast ( - void * src - ) const -{ - return TAO::Object_Cast<T>::tao_upcast (src); -} - // ************************************************************* // Operations for class TAO_Unbounded_Pseudo_Sequence // ************************************************************* diff --git a/TAO/tao/Sequence_T.h b/TAO/tao/Sequence_T.h index 75443191b78..0fa99132c7b 100644 --- a/TAO/tao/Sequence_T.h +++ b/TAO/tao/Sequence_T.h @@ -255,29 +255,6 @@ template<typename T, class TAO_Bounded_Object_Sequence; template<size_t MAX> class TAO_Bounded_String_Sequence; -// ************************************************************* - -namespace TAO -{ - /** - * @struct Object_Cast - * - * @brief Specialized in generated code. - * - */ - template<typename T> - struct Object_Cast - { - static T * tao_narrow ( - CORBA::Object_ptr - ACE_ENV_ARG_DECL - ); - static CORBA::Object_ptr tao_upcast (void *); - }; -}; - -// ************************************************************* - /** * @class TAO_Object_Manager * @@ -606,10 +583,6 @@ public: virtual void _deallocate_buffer (void); virtual void _shrink_buffer (CORBA::ULong new_length, CORBA::ULong old_length); - virtual void _downcast (void * target, - CORBA::Object_ptr src - ACE_ENV_ARG_DECL_WITH_DEFAULTS); - virtual CORBA::Object_ptr _upcast (void * src) const; }; // ************************************************************* @@ -677,10 +650,6 @@ public: virtual void _deallocate_buffer (void); virtual void _shrink_buffer (CORBA::ULong new_length, CORBA::ULong old_length); - virtual void _downcast (void * target, - CORBA::Object_ptr src - ACE_ENV_ARG_DECL_WITH_DEFAULTS); - virtual CORBA::Object_ptr _upcast (void * src) const; }; // ************************************************************* diff --git a/TAO/tao/Valuetype/Sequence_T.inl b/TAO/tao/Valuetype/Sequence_T.inl index d36e355b374..f8bbada422e 100644 --- a/TAO/tao/Valuetype/Sequence_T.inl +++ b/TAO/tao/Valuetype/Sequence_T.inl @@ -83,7 +83,7 @@ ACE_INLINE T *& TAO_Valuetype_Manager<T,T_var,T_life>::out (void) { - T_life::tao_remove_ref (*this->ptr_); + TAO::Value_Traits<T>::tao_remove_ref (*this->ptr_); *this->ptr_ = 0; return *this->ptr_; } diff --git a/TAO/tao/Valuetype/Value_VarOut_T.cpp b/TAO/tao/Valuetype/Value_VarOut_T.cpp index 9ee88a39c8f..6b3bbb8b541 100644 --- a/TAO/tao/Valuetype/Value_VarOut_T.cpp +++ b/TAO/tao/Valuetype/Value_VarOut_T.cpp @@ -9,6 +9,22 @@ ACE_RCSID (tao, Value_VarOut_T, "$Id$") +template<typename T> +void +TAO::Value_Traits<T>::tao_add_ref (T * p) +{ + CORBA::add_ref (p); +} + +template<typename T> +void +TAO::Value_Traits<T>::tao_remove_ref (T * p) +{ + CORBA::remove_ref (p); +} + +// =============================================================== + template <typename T, typename T_life> TAO_Value_Var_T<T,T_life>::TAO_Value_Var_T (void) : ptr_ (0) @@ -36,21 +52,21 @@ TAO_Value_Var_T<T,T_life>::TAO_Value_Var_T ( const TAO_Value_Var_T<T,T_life> & p ) { - T_life::tao_add_ref (p.ptr ()); + TAO::Value_Traits<T>::tao_add_ref (p.ptr ()); this->ptr_ = p.ptr (); } template <typename T, typename T_life> TAO_Value_Var_T<T,T_life>::~TAO_Value_Var_T (void) { - T_life::tao_remove_ref (this->ptr_); + TAO::Value_Traits<T>::tao_remove_ref (this->ptr_); } template <typename T, typename T_life> TAO_Value_Var_T<T,T_life> & TAO_Value_Var_T<T,T_life>::operator= (T * p) { - T_life::tao_remove_ref (this->ptr_); + TAO::Value_Traits<T>::tao_remove_ref (this->ptr_); this->ptr_ = p; return *this; } @@ -61,9 +77,9 @@ TAO_Value_Var_T<T,T_life>::operator= (const TAO_Value_Var_T & p) { if (this != &p) { - T_life::tao_remove_ref (this->ptr_); + TAO::Value_Traits<T>::tao_remove_ref (this->ptr_); T * tmp = p.ptr (); - T_life::tao_add_ref (tmp); + TAO::Value_Traits<T>::tao_add_ref (tmp); this->ptr_ = tmp; } @@ -107,7 +123,7 @@ template <typename T, typename T_life> T *& TAO_Value_Var_T<T,T_life>::out (void) { - T_life::tao_remove_ref (this->ptr_); + TAO::Value_Traits<T>::tao_remove_ref (this->ptr_); this->ptr_ = 0; return this->ptr_; } @@ -134,7 +150,7 @@ template <typename T, typename T_life> TAO_Value_Out_T<T,T_life>::TAO_Value_Out_T (TAO_Value_Var_T<T,T_life> & p) : ptr_ (p.out ()) { - T_life::tao_remove_ref (this->ptr_); + TAO::Value_Traits<T>::tao_remove_ref (this->ptr_); this->ptr_ = 0; } @@ -156,7 +172,7 @@ TAO_Value_Out_T<T,T_life> & TAO_Value_Out_T<T,T_life>::operator= (const TAO_Value_Var_T<T,T_life> & p) { T * tmp = p.ptr (); - T_life::tao_add_ref (tmp); + TAO::Value_Traits<T>::tao_add_ref (tmp); this->ptr_ = tmp; return *this; } diff --git a/TAO/tao/Valuetype/Value_VarOut_T.h b/TAO/tao/Valuetype/Value_VarOut_T.h index a2fcee4223e..320542876db 100644 --- a/TAO/tao/Valuetype/Value_VarOut_T.h +++ b/TAO/tao/Valuetype/Value_VarOut_T.h @@ -20,6 +20,22 @@ # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ +namespace TAO +{ + /** + * struct Value_Traits + * + * @brief Specialized for each valuetype in generated code. + * + */ + template<typename T> + struct Value_Traits + { + static void tao_add_ref (T *); + static void tao_remove_ref (T *); + }; +}; + /** * @class TAO_Value_Var_T * |