From 1393675c806a3b73dba453945e9c5dfcfb774789 Mon Sep 17 00:00:00 2001 From: parsons Date: Wed, 13 Jan 2010 23:19:17 +0000 Subject: ChangeLogTag: Wed Jan 13 23:16:57 UTC 2010 Jeff Parsons --- modules/TAO/ChangeLog | 16 ++ modules/TAO/TAO_IDL/ast/ast_argument.cpp | 2 - modules/TAO/TAO_IDL/ast/ast_attribute.cpp | 74 +++-- .../TAO_IDL/be/be_visitor_operation/arglist.cpp | 4 - .../be/be_visitor_operation/exceptlist_cs.cpp | 3 +- modules/TAO/TAO_IDL/be/be_visitor_reifying.cpp | 18 ++ .../TAO/TAO_IDL/be/be_visitor_tmpl_module_inst.cpp | 297 ++++++++++++++++++++- .../TAO/TAO_IDL/be_include/be_visitor_reifying.h | 2 + .../be_include/be_visitor_tmpl_module_inst.h | 8 + modules/TAO/TAO_IDL/util/utl_err.cpp | 4 - 10 files changed, 369 insertions(+), 59 deletions(-) diff --git a/modules/TAO/ChangeLog b/modules/TAO/ChangeLog index 322414a81a2..d8e7a65498f 100644 --- a/modules/TAO/ChangeLog +++ b/modules/TAO/ChangeLog @@ -1,3 +1,19 @@ +Wed Jan 13 23:16:57 UTC 2010 Jeff Parsons + + * TAO_IDL/be/be_visitor_tmpl_module_inst.cpp: + * TAO_IDL/be/be_visitor_operation/arglist.cpp: + * TAO_IDL/be/be_visitor_operation/exceptlist_cs.cpp: + * TAO_IDL/be/be_visitor_reifying.cpp: + * TAO_IDL/ast/ast_attribute.cpp: + * TAO_IDL/ast/ast_argument.cpp: + * TAO_IDL/be_include/be_visitor_reifying.h: + * TAO_IDL/be_include/be_visitor_tmpl_module_inst.h: + * TAO_IDL/util/utl_err.cpp: + + Added support for template instantiation of contained + interfaces, operations, attributes, and the associated + arguments and exception lists. + Tue Jan 12 22:45:58 UTC 2010 Jeff Parsons * TAO_IDL/include/utl_scope.h: diff --git a/modules/TAO/TAO_IDL/ast/ast_argument.cpp b/modules/TAO/TAO_IDL/ast/ast_argument.cpp index 1b46a649838..1ace9b13072 100644 --- a/modules/TAO/TAO_IDL/ast/ast_argument.cpp +++ b/modules/TAO/TAO_IDL/ast/ast_argument.cpp @@ -141,6 +141,4 @@ AST_Argument::direction (void) return this->pd_direction; } - - IMPL_NARROW_FROM_DECL(AST_Argument) diff --git a/modules/TAO/TAO_IDL/ast/ast_attribute.cpp b/modules/TAO/TAO_IDL/ast/ast_attribute.cpp index f11b57a26ca..9292ba803be 100644 --- a/modules/TAO/TAO_IDL/ast/ast_attribute.cpp +++ b/modules/TAO/TAO_IDL/ast/ast_attribute.cpp @@ -118,8 +118,10 @@ AST_Attribute::~AST_Attribute (void) void AST_Attribute::dump (ACE_OSTREAM_TYPE &o) { - this->dump_i (o, (this->pd_readonly == true ? - "readonly attribute " : "attribute ")); + this->dump_i (o, (this->pd_readonly == true + ? "readonly attribute " + : "attribute ")); + this->AST_Field::dump (o); } @@ -210,7 +212,7 @@ UTL_NameList * AST_Attribute::fe_add_get_exceptions (UTL_NameList *t) { UTL_ScopedName *nl_n = 0; - AST_Exception *fe = 0; + AST_Type *fe = 0; AST_Decl *d = 0; this->pd_get_exceptions = 0; @@ -219,39 +221,37 @@ AST_Attribute::fe_add_get_exceptions (UTL_NameList *t) { nl_n = nl_i.item (); - d = this->defined_in ()->lookup_by_name (nl_n, - true); + d = this->defined_in ()->lookup_by_name (nl_n, true); - if (d == 0 || d->node_type() != AST_Decl::NT_except) + if (d == 0) { idl_global->err ()->lookup_error (nl_n); return 0; } + + AST_Decl::NodeType nt = d->node_type (); - fe = AST_Exception::narrow_from_decl (d); - - if (fe == 0) + if (nt != AST_Decl::NT_except + && nt != AST_Decl::NT_param_holder) { idl_global->err ()->error1 (UTL_Error::EIDL_ILLEGAL_RAISES, - this); + this); return 0; } + fe = AST_Type::narrow_from_decl (d); + + UTL_ExceptList *el = 0; + ACE_NEW_RETURN (el, + UTL_ExceptList (fe, 0), + 0); + if (this->pd_get_exceptions == 0) { - ACE_NEW_RETURN (this->pd_get_exceptions, - UTL_ExceptList (fe, - 0), - 0); + this->pd_get_exceptions = el; } else { - UTL_ExceptList *el = 0; - ACE_NEW_RETURN (el, - UTL_ExceptList (fe, - 0), - 0); - this->pd_get_exceptions->nconc (el); } } @@ -265,7 +265,7 @@ UTL_NameList * AST_Attribute::fe_add_set_exceptions (UTL_NameList *t) { UTL_ScopedName *nl_n = 0; - AST_Exception *fe = 0; + AST_Type *fe = 0; AST_Decl *d = 0; this->pd_set_exceptions = 0; @@ -274,39 +274,37 @@ AST_Attribute::fe_add_set_exceptions (UTL_NameList *t) { nl_n = nl_i.item (); - d = this->defined_in ()->lookup_by_name (nl_n, - true); + d = this->defined_in ()->lookup_by_name (nl_n, true); - if (d == 0 || d->node_type() != AST_Decl::NT_except) + if (d == 0) { idl_global->err ()->lookup_error (nl_n); return 0; } + + AST_Decl::NodeType nt = d->node_type (); - fe = AST_Exception::narrow_from_decl (d); - - if (fe == 0) + if (nt != AST_Decl::NT_except + && nt != AST_Decl::NT_param_holder) { idl_global->err ()->error1 (UTL_Error::EIDL_ILLEGAL_RAISES, - this); + this); return 0; } + fe = AST_Type::narrow_from_decl (d); + + UTL_ExceptList *el = 0; + ACE_NEW_RETURN (el, + UTL_ExceptList (fe, 0), + 0); + if (this->pd_set_exceptions == 0) { - ACE_NEW_RETURN (this->pd_set_exceptions, - UTL_ExceptList (fe, - 0), - 0); + this->pd_set_exceptions = el; } else { - UTL_ExceptList *el = 0; - ACE_NEW_RETURN (el, - UTL_ExceptList (fe, - 0), - 0); - this->pd_set_exceptions->nconc (el); } } diff --git a/modules/TAO/TAO_IDL/be/be_visitor_operation/arglist.cpp b/modules/TAO/TAO_IDL/be/be_visitor_operation/arglist.cpp index b692a14bb75..9ed77596b7c 100644 --- a/modules/TAO/TAO_IDL/be/be_visitor_operation/arglist.cpp +++ b/modules/TAO/TAO_IDL/be/be_visitor_operation/arglist.cpp @@ -18,10 +18,6 @@ // // ============================================================================ -ACE_RCSID (be_visitor_operation, - arglist, - "$Id$") - // ************************************************************ // operation visitor to generate the argument list. // We have separated code generation for this from the 4 main diff --git a/modules/TAO/TAO_IDL/be/be_visitor_operation/exceptlist_cs.cpp b/modules/TAO/TAO_IDL/be/be_visitor_operation/exceptlist_cs.cpp index e5526734133..cc1ecbc87fe 100644 --- a/modules/TAO/TAO_IDL/be/be_visitor_operation/exceptlist_cs.cpp +++ b/modules/TAO/TAO_IDL/be/be_visitor_operation/exceptlist_cs.cpp @@ -60,7 +60,8 @@ be_visitor_operation_exceptlist_cs::visit_operation (be_operation *node) for (UTL_ExceptlistActiveIterator ei (node->exceptions ()); !ei.is_done ();) { - ex = be_exception::narrow_from_decl (ei.item ()); + AST_Decl *d = ei.item (); + ex = be_exception::narrow_from_decl (d); *os << "{" << be_idt_nl << "\"" << ex->repoID () << "\"," << be_nl diff --git a/modules/TAO/TAO_IDL/be/be_visitor_reifying.cpp b/modules/TAO/TAO_IDL/be/be_visitor_reifying.cpp index 3148858114b..014c9637eaa 100644 --- a/modules/TAO/TAO_IDL/be/be_visitor_reifying.cpp +++ b/modules/TAO/TAO_IDL/be/be_visitor_reifying.cpp @@ -11,6 +11,8 @@ #include "be_visitor_context.h" #include "be_interface.h" +#include "be_exception.h" +#include "be_typedef.h" #include "be_array.h" #include "be_sequence.h" #include "be_predefined_type.h" @@ -66,6 +68,22 @@ be_visitor_reifying::visit_interface (be_interface *node) return 0; } +int +be_visitor_reifying::visit_exception (be_exception *node) +{ + this->reified_node_ = node; + + return 0; +} + +int +be_visitor_reifying::visit_typedef (be_typedef *node) +{ + this->reified_node_ = node; + + return 0; +} + int be_visitor_reifying::visit_array (be_array *node) { diff --git a/modules/TAO/TAO_IDL/be/be_visitor_tmpl_module_inst.cpp b/modules/TAO/TAO_IDL/be/be_visitor_tmpl_module_inst.cpp index 7ad9ffc285d..d8deb67fe20 100644 --- a/modules/TAO/TAO_IDL/be/be_visitor_tmpl_module_inst.cpp +++ b/modules/TAO/TAO_IDL/be/be_visitor_tmpl_module_inst.cpp @@ -15,6 +15,10 @@ #include "be_module.h" #include "be_template_module.h" #include "be_template_module_inst.h" +#include "be_interface.h" +#include "be_attribute.h" +#include "be_operation.h" +#include "be_argument.h" #include "be_typedef.h" #include "be_constant.h" #include "be_structure.h" @@ -23,6 +27,12 @@ #include "ast_param_holder.h" +#include "utl_namelist.h" +#include "utl_identifier.h" +#include "utl_exceptlist.h" + +#include "fe_interface_header.h" + be_visitor_tmpl_module_inst::be_visitor_tmpl_module_inst ( be_visitor_context *ctx) : be_visitor_scope (ctx) @@ -152,6 +162,231 @@ be_visitor_tmpl_module_inst::visit_template_module_inst ( return 0; } +int +be_visitor_tmpl_module_inst::visit_interface (be_interface *node) +{ + if (this->ctx_->template_args () == 0) + { + return 0; + } + + UTL_Scope *s = node->defined_in (); + UTL_NameList *parent_names = 0; + + // We're at global scope here so we need to fool the scope stack + // for a minute so the correct repo id can be calculated at + // interface construction time. + idl_global->scopes ().push (s); + + for (long i = 0; i < node->n_inherits (); ++i) + { + AST_Type *parent = + AST_Type::narrow_from_decl (this->reify_type ( + node->inherits ()[i])); + + // We copy each name added so we can call destroy() on the + // list, which disposes of the contents as well as the + // nested tail pointers. + UTL_NameList *parent_name = 0; + ACE_NEW_RETURN (parent_name, + UTL_NameList (parent->name ()->copy (), 0), + -1); + + if (parent_names == 0) + { + parent_names = parent_name; + } + else + { + parent_names->nconc (parent_name); + } + } + + // Back to reality. + idl_global->scopes ().pop (); + + // Now set the scope to our adding scope. + s = this->ctx_->template_module_inst_scope (); + idl_global->scopes ().push (s); + + Identifier *node_id = 0; + ACE_NEW_RETURN (node_id, + Identifier (node->local_name ()), + -1); + + UTL_ScopedName *local_name = 0; + ACE_NEW_RETURN (local_name, + UTL_ScopedName (node_id, 0), + -1); + + FE_InterfaceHeader header (local_name, + parent_names, + node->is_local (), + node->is_abstract (), + true); + + be_interface *added_iface = 0; + ACE_NEW_RETURN (added_iface, + be_interface (header.name (), + header.inherits (), + header.n_inherits (), + header.inherits_flat (), + header.n_inherits_flat (), + header.is_local (), + header.is_abstract ()), + -1); + + parent_names->destroy (); + delete parent_names; + parent_names = 0; + + // Back to reality. + idl_global->scopes ().pop (); + + added_iface->set_defined_in (s); + added_iface->set_imported (node->imported ()); + + // Set repo id to 0, so it will be recomputed on the next access, + // and set the prefix to the eventtype's prefix. All this is + // necessary in case the eventtype's prefix was modified after + // its declaration. We assume 'implied IDL' means that the + // derived event consumer interface should have the same prefix. + added_iface->AST_Decl::repoID (0); + added_iface->prefix (const_cast (node->prefix ())); + + const char *repo_id = added_iface->repoID (); + + // For interfaces, this should always be a module or root, and + // AST_Root is a subclass of AST_Module. + AST_Module *m = AST_Module::narrow_from_scope (s); + + m->be_add_interface (added_iface); + + // Save our containing scope for restoration later. + be_scope *holder = this->ctx_->template_module_inst_scope (); + + // Update the adding scope for the interface contents. + this->ctx_->template_module_inst_scope (added_iface); + + if (this->visit_scope (node) != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("be_visitor_tmpl_module_inst::") + ACE_TEXT ("visit_interface - ") + ACE_TEXT ("visit_scope failed\n")), + -1); + } + + // Restore the previous scope. + this->ctx_->template_module_inst_scope (holder); + + return 0; +} + +int +be_visitor_tmpl_module_inst::visit_attribute (be_attribute *node) +{ + AST_Type *ft = + AST_Type::narrow_from_decl ( + this->reify_type (node->field_type ())); + + be_attribute *added_attr = 0; + ACE_NEW_RETURN (added_attr, + be_attribute (node->readonly (), + ft, + node->name (), + node->is_local (), + node->is_abstract ()), + -1); + + be_scope *s = this->ctx_->template_module_inst_scope (); + added_attr->set_defined_in (s); + s->add_to_scope (added_attr); + + // Force recalculation of our repo ID based on the new scope. + added_attr->repoID (0); + const char *dummy = added_attr->repoID (); + + // These will work even if the exception lists are null. + + UTL_ExceptList *old_ex = node->get_get_exceptions (); + UTL_ExceptList *new_ex = this->reify_exception_list (old_ex); + added_attr->be_add_get_exceptions (new_ex); + + old_ex = node->get_set_exceptions (); + new_ex = this->reify_exception_list (old_ex); + added_attr->be_add_set_exceptions (new_ex); + + return 0; +} + +int +be_visitor_tmpl_module_inst::visit_operation (be_operation *node) +{ + AST_Type *rt = + AST_Type::narrow_from_decl ( + this->reify_type (node->return_type ())); + + Identifier id (node->local_name ()->get_string ()); + UTL_ScopedName sn (&id, 0); + + be_operation *added_op = 0; + ACE_NEW_RETURN (added_op, + be_operation (rt, + node->flags (), + &sn, + node->is_local (), + node->is_abstract ()), + -1); + + be_scope *s = this->ctx_->template_module_inst_scope (); + s->add_to_scope (added_op); + added_op->set_defined_in (s); + + this->ctx_->template_module_inst_scope (added_op); + + if (this->visit_scope (node) != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("be_visitor_tmpl_module_inst::") + ACE_TEXT ("visit_operation - ") + ACE_TEXT ("visit_scope failed\n")), + -1); + } + + this->ctx_->template_module_inst_scope (s); + + UTL_ExceptList *new_ex = + this->reify_exception_list (node->exceptions ()); + + added_op->be_add_exceptions (new_ex); + + return 0; +} + +int +be_visitor_tmpl_module_inst::visit_argument (be_argument *node) +{ + AST_Type *t = + AST_Type::narrow_from_decl ( + this->reify_type (node->field_type ())); + + be_argument *arg = 0; + ACE_NEW_RETURN (arg, + be_argument (node->direction (), + t, + node->name ()), + -1); + + be_operation *op = + be_operation::narrow_from_scope ( + this->ctx_->template_module_inst_scope ()); + + op->be_add_argument (arg); + + return 0; +} + int be_visitor_tmpl_module_inst::visit_typedef (be_typedef *node) { @@ -164,15 +399,17 @@ be_visitor_tmpl_module_inst::visit_typedef (be_typedef *node) AST_Type::narrow_from_decl ( this->reify_type (node->base_type ())); - be_typedef *td = 0; - ACE_NEW_RETURN (td, + be_typedef *added_td = 0; + ACE_NEW_RETURN (added_td, be_typedef (bt, node->name (), false, false), -1); - this->ctx_->template_module_inst_scope ()->add_to_scope (td); + be_scope *s = this->ctx_->template_module_inst_scope (); + added_td->set_defined_in (s); + s->add_to_scope (added_td); return 0; } @@ -223,12 +460,14 @@ be_visitor_tmpl_module_inst::visit_constant (be_constant *node) be_expression (v, et), -1); - be_constant *new_c = 0; - ACE_NEW_RETURN (new_c, + be_constant *added_const = 0; + ACE_NEW_RETURN (added_const, be_constant (et, new_v, node->name ()), -1); - this->ctx_->template_module_inst_scope ()->add_to_scope (new_c); + be_scope *s = this->ctx_->template_module_inst_scope (); + added_const->set_defined_in (s); + s->add_to_scope (added_const); return 0; } @@ -241,8 +480,8 @@ be_visitor_tmpl_module_inst::visit_structure (be_structure *node) return 0; } - be_structure *s = 0; - ACE_NEW_RETURN (s, + be_structure *added_struct = 0; + ACE_NEW_RETURN (added_struct, be_structure (node->name (), node->is_local (), node->is_abstract ()), @@ -251,10 +490,12 @@ be_visitor_tmpl_module_inst::visit_structure (be_structure *node) // Hold current scope for restoration later. be_scope *holder = this->ctx_->template_module_inst_scope (); - holder->add_to_scope (s); + holder->add_to_scope (added_struct); + added_struct->set_defined_in (holder); + // Store the new scope for traversal. - this->ctx_->template_module_inst_scope (s); + this->ctx_->template_module_inst_scope (added_struct); if (this->visit_scope (node) != 0) { @@ -310,3 +551,39 @@ be_visitor_tmpl_module_inst::reify_type (AST_Decl *d) return rv.reified_node (); } + +UTL_ExceptList * +be_visitor_tmpl_module_inst::reify_exception_list ( + UTL_ExceptList *orig) +{ + if (orig == 0) + { + return 0; + } + + UTL_ExceptList *retval = 0; + + for (UTL_ExceptlistActiveIterator i (orig); + !i.is_done (); + i.next ()) + { + AST_Type *ex = + AST_Type::narrow_from_decl (this->reify_type (i.item ())); + + UTL_ExceptList *ex_list = 0; + ACE_NEW_RETURN (ex_list, + UTL_ExceptList (ex, 0), + 0); + + if (retval == 0) + { + retval = ex_list; + } + else + { + retval->nconc (ex_list); + } + } + + return retval; +} \ No newline at end of file diff --git a/modules/TAO/TAO_IDL/be_include/be_visitor_reifying.h b/modules/TAO/TAO_IDL/be_include/be_visitor_reifying.h index ceed34503e6..64067a3abe0 100644 --- a/modules/TAO/TAO_IDL/be_include/be_visitor_reifying.h +++ b/modules/TAO/TAO_IDL/be_include/be_visitor_reifying.h @@ -54,6 +54,8 @@ public: AST_Decl *reified_node (void) const; virtual int visit_interface (be_interface *node); + virtual int visit_exception (be_exception *node); + virtual int visit_typedef (be_typedef *node); virtual int visit_array (be_array *node); virtual int visit_sequence (be_sequence *node); virtual int visit_predefined_type (be_predefined_type *node); diff --git a/modules/TAO/TAO_IDL/be_include/be_visitor_tmpl_module_inst.h b/modules/TAO/TAO_IDL/be_include/be_visitor_tmpl_module_inst.h index a917106e188..5c16ec97694 100644 --- a/modules/TAO/TAO_IDL/be_include/be_visitor_tmpl_module_inst.h +++ b/modules/TAO/TAO_IDL/be_include/be_visitor_tmpl_module_inst.h @@ -31,6 +31,7 @@ class be_template_module_inst; class AST_Type; +class UTL_ExceptList; class be_visitor_tmpl_module_inst : public be_visitor_scope { @@ -51,6 +52,10 @@ public: virtual int visit_module (be_module *node); virtual int visit_template_module (be_template_module *node); virtual int visit_template_module_inst (be_template_module_inst *node); + virtual int visit_interface (be_interface *node); + virtual int visit_attribute (be_attribute *node); + virtual int visit_operation (be_operation *node); + virtual int visit_argument (be_argument *node); virtual int visit_typedef (be_typedef *node); virtual int visit_constant (be_constant *node); virtual int visit_structure (be_structure *node); @@ -62,6 +67,9 @@ private: // the scope of a template module, the returned node will be a // copy created in the scope of the template module instantiation. AST_Decl *reify_type (AST_Decl *d); + + // Utility method used for attributes and operations. + UTL_ExceptList *reify_exception_list (UTL_ExceptList *orig); }; #endif // TAO_BE_VISITOR_TMPL_MODULE_INST_H diff --git a/modules/TAO/TAO_IDL/util/utl_err.cpp b/modules/TAO/TAO_IDL/util/utl_err.cpp index 0fc48b4782e..6b310af010b 100644 --- a/modules/TAO/TAO_IDL/util/utl_err.cpp +++ b/modules/TAO/TAO_IDL/util/utl_err.cpp @@ -84,10 +84,6 @@ trademarks or registered trademarks of Sun Microsystems, Inc. #include "ace/Log_Msg.h" -ACE_RCSID (util, - utl_err, - "$Id$") - // Convert an error code into a const char * static const char * error_string (UTL_Error::ErrorCode c) -- cgit v1.2.1