diff options
author | parsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2010-01-21 20:22:01 +0000 |
---|---|---|
committer | parsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2010-01-21 20:22:01 +0000 |
commit | 1491848b683b01791b7936a285b3b9f617bc456a (patch) | |
tree | b6321573f5688a080b6e61da686b5052e8415d97 | |
parent | b25678db1c641614bdc4e742245f005f687fe1e4 (diff) | |
download | ATCD-1491848b683b01791b7936a285b3b9f617bc456a.tar.gz |
ChangeLogTag: Thu Jan 21 20:20:47 UTC 2010 Jeff Parsons <j.parsons@vanderbilt.edu>
29 files changed, 1954 insertions, 159 deletions
diff --git a/modules/TAO/ChangeLog b/modules/TAO/ChangeLog index 60a5d18571b..c960740a848 100644 --- a/modules/TAO/ChangeLog +++ b/modules/TAO/ChangeLog @@ -1,3 +1,53 @@ +Thu Jan 21 20:20:47 UTC 2010 Jeff Parsons <j.parsons@vanderbilt.edu> + + * TAO_IDL/include/ast_visitor_reifying.h: + * TAO_IDL/include/ast_visitor_tmpl_module_inst.h: + * TAO_IDL/include/ast_visitor_context.h: + * TAO_IDL/ast/ast_visitor_tmpl_module_inst.cpp: + * TAO_IDL/ast/ast_visitor_reifying.cpp: + * TAO_IDL/ast/ast_visitor_context.cpp: + + Moved the visitors that create implied IDL upon + template module instantiation to the front end, + along with a piece of the visitor context class + that becomes a base class for the backend visitor + context class. This move is motivated by the fact + that generation of executor IDL turns this implied + IDL into explicit IDL, so in order to parse the + executor IDL file, this implied IDL must be added + to the AST in the front end. + + The corresponding backend visitor classes will be + removed after further testing. + + * TAO_IDL/include/ast_factory.h: + * TAO_IDL/include/ast_operation.h: + * TAO_IDL/be/be_factory.cpp: + * TAO_IDL/be/be_visitor_scope.cpp: + * TAO_IDL/be/be_visitor_interface/interface_ex_idl.cpp: + * TAO_IDL/be/be_visitor_module.cpp: + * TAO_IDL/be/be_produce.cpp: + * TAO_IDL/be/be_visitor_context.cpp: + * TAO_IDL/be/be_visitor.cpp: + * TAO_IDL/be/be_operation.cpp: + * TAO_IDL/be/be_scope.cpp: + * TAO_IDL/be/be_generator.cpp: + * TAO_IDL/ast/ast_visitor.cpp: + * TAO_IDL/ast/ast_operation.cpp: + * TAO_IDL/ast/ast_generator.cpp: + * TAO_IDL/ast/ast_factory.cpp: + * TAO_IDL/be_include/be_operation.h: + * TAO_IDL/be_include/be_visitor_context.h: + * TAO_IDL/be_include/be_factory.h: + * TAO_IDL/be_include/be_scope.h: + * TAO_IDL/fe/fe_interface_header.cpp: + * TAO_IDL/util/utl_scope.cpp: + + Other changes related to the above visitor move, plus + some cosmetic changes. Spawning of the new visitors + when a template module instantiation is seen is not + added in this set of changes. + Mon Jan 18 15:35:54 UTC 2010 Jeff Parsons <j.parsons@vanderbilt.edu> * TAO_IDL/be/be_visitor_valuebox/field_ci.cpp: diff --git a/modules/TAO/TAO_IDL/ast/ast_factory.cpp b/modules/TAO/TAO_IDL/ast/ast_factory.cpp index 7bd68aa85a7..b04773ea070 100644 --- a/modules/TAO/TAO_IDL/ast/ast_factory.cpp +++ b/modules/TAO/TAO_IDL/ast/ast_factory.cpp @@ -151,6 +151,23 @@ AST_Factory::destroy (void) this->UTL_Scope::destroy (); } +UTL_ExceptList * +AST_Factory::be_add_exceptions (UTL_ExceptList *t) +{ + if (this->pd_exceptions != 0) + { + idl_global->err ()->error1 (UTL_Error::EIDL_ILLEGAL_RAISES, + this); + } + else + { + this->pd_exceptions = t; + this->pd_n_exceptions = (t == 0 ? 0 : t->length ()); + } + + return this->pd_exceptions; +} + // Private operations. // Compute total number of members. @@ -342,7 +359,5 @@ AST_Factory::ast_accept (ast_visitor *visitor) // Data accessors - - IMPL_NARROW_FROM_DECL(AST_Factory) IMPL_NARROW_FROM_SCOPE(AST_Factory) diff --git a/modules/TAO/TAO_IDL/ast/ast_generator.cpp b/modules/TAO/TAO_IDL/ast/ast_generator.cpp index 87083dc4c08..358f8eee92a 100644 --- a/modules/TAO/TAO_IDL/ast/ast_generator.cpp +++ b/modules/TAO/TAO_IDL/ast/ast_generator.cpp @@ -129,7 +129,7 @@ AST_Module * AST_Generator::create_module (UTL_Scope *s, UTL_ScopedName *n) { - // We create this first so if we find a module with the + // We create this first so if we find a module with the // same name from an included file, we can add its // members to the new module's scope. AST_Module *retval = 0; @@ -137,57 +137,59 @@ AST_Generator::create_module (UTL_Scope *s, AST_Module (n), 0); - AST_Decl *d = 0; AST_Module *m = 0; - UTL_ScopeActiveIterator iter (s, - UTL_Scope::IK_decls); - // Check for another module of the same name in this scope. - while (!iter.is_done ()) + for (UTL_ScopeActiveIterator iter (s, UTL_Scope::IK_decls); + !iter.is_done (); + iter.next ()) { - d = iter.item (); + // Can't just check node type here, since it could be a + // template module or template module instantiation. + m = AST_Module::narrow_from_decl (iter.item ()); - if (d->node_type () == AST_Decl::NT_module) + if (m != 0) { // Does it have the same name as the one we're // supposed to create. - if (d->local_name ()->compare (n->last_component ())) + if (m->local_name ()->compare (n->last_component ())) { - m = AST_Module::narrow_from_decl (d); - // Get m's previous_ member, plus all it's decls, // into the new modules's previous_ member. retval->add_to_previous (m); + retval->prefix (const_cast<char *> (m->prefix ())); } } - - iter.next (); } // If this scope is itself a module, and has been previously // opened, the previous opening may contain a previous opening // of the module we're creating. - d = ScopeAsDecl (s); + AST_Decl *d = ScopeAsDecl (s); AST_Decl::NodeType nt = d->node_type (); if (nt == AST_Decl::NT_module || nt == AST_Decl::NT_root) { + // Also check this to week out a template module or its + // instantiation. m = AST_Module::narrow_from_decl (d); - // AST_Module::previous_ is a set, so it contains each - // entry only once, but previous_ will contain the decls - // from all previous openings. See comment in - // AST_Module::add_to_previous() body. - d = m->look_in_previous (n->last_component ()); - - if (d != 0) + if (m != 0) { - if (d->node_type () == AST_Decl::NT_module) + // AST_Module::previous_ is a set, so it contains each + // entry only once, but previous_ will contain the decls + // from all previous openings. See comment in + // AST_Module::add_to_previous() body. + d = m->look_in_previous (n->last_component ()); + + if (d != 0) { - m = AST_Module::narrow_from_decl (d); + if (d->node_type () == AST_Decl::NT_module) + { + m = AST_Module::narrow_from_decl (d); - retval->add_to_previous (m); + retval->add_to_previous (m); + } } } } diff --git a/modules/TAO/TAO_IDL/ast/ast_operation.cpp b/modules/TAO/TAO_IDL/ast/ast_operation.cpp index b2d4144b757..bbcc676a0e1 100644 --- a/modules/TAO/TAO_IDL/ast/ast_operation.cpp +++ b/modules/TAO/TAO_IDL/ast/ast_operation.cpp @@ -218,6 +218,22 @@ AST_Operation::destroy (void) this->AST_Decl::destroy (); } +UTL_ExceptList * +AST_Operation::be_add_exceptions (UTL_ExceptList *t) +{ + if (this->pd_exceptions != 0) + { + idl_global->err ()->error1 (UTL_Error::EIDL_ILLEGAL_RAISES, + this); + } + else + { + this->pd_exceptions = t; + } + + return this->pd_exceptions; +} + // Private operations. // Compute total number of members. diff --git a/modules/TAO/TAO_IDL/ast/ast_visitor.cpp b/modules/TAO/TAO_IDL/ast/ast_visitor.cpp index 35c8f8566f6..9fa7462c7fa 100644 --- a/modules/TAO/TAO_IDL/ast/ast_visitor.cpp +++ b/modules/TAO/TAO_IDL/ast/ast_visitor.cpp @@ -3,10 +3,6 @@ #include "ast_visitor.h" #include "ace/config-all.h" -ACE_RCSID (ast, - ast_visitor, - "$Id$") - ast_visitor::ast_visitor (void) { } diff --git a/modules/TAO/TAO_IDL/ast/ast_visitor_context.cpp b/modules/TAO/TAO_IDL/ast/ast_visitor_context.cpp new file mode 100644 index 00000000000..29b95abb1b6 --- /dev/null +++ b/modules/TAO/TAO_IDL/ast/ast_visitor_context.cpp @@ -0,0 +1,62 @@ +// +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO_IDL_FE +// +// = FILENAME +// ast_visitor_context.cpp +// +// = DESCRIPTION +// Maintains the context information for visitors +// +// = AUTHOR +// Jeff Parsons & Aniruddha Gokhale +// +// ============================================================================ + +#include "ast_visitor_context.h" + +ast_visitor_context::ast_visitor_context (void) + : template_params_ (0), + template_args_ (0) +{ +} + +ast_visitor_context::ast_visitor_context (const ast_visitor_context &ctx) + : template_params_ (ctx.template_params_), + template_args_ (ctx.template_args_) +{ +} + +ast_visitor_context::~ast_visitor_context (void) +{ +} + +FE_Utils::T_PARAMLIST_INFO * +ast_visitor_context::template_params (void) const +{ + return this->template_params_; +} + +void +ast_visitor_context::template_params (FE_Utils::T_PARAMLIST_INFO *params) +{ + this->template_params_ = params; +} + +FE_Utils::T_ARGLIST * +ast_visitor_context::template_args (void) const +{ + return this->template_args_; +} + +void +ast_visitor_context::template_args (FE_Utils::T_ARGLIST *args) +{ + this->template_args_ = args; +} + diff --git a/modules/TAO/TAO_IDL/ast/ast_visitor_reifying.cpp b/modules/TAO/TAO_IDL/ast/ast_visitor_reifying.cpp new file mode 100644 index 00000000000..323f43236f5 --- /dev/null +++ b/modules/TAO/TAO_IDL/ast/ast_visitor_reifying.cpp @@ -0,0 +1,577 @@ +/** + * @file ast_visitor_reifying.cpp + * + * $Id$ + * + * @author Jeff Parsons + */ +//============================================================================= + +#include "ast_visitor_reifying.h" +#include "ast_visitor_context.h" +#include "ast_generator.h" + +#include "ast_interface.h" +#include "ast_valuetype.h" +#include "ast_eventtype.h" +#include "ast_component.h" +#include "ast_exception.h" +#include "ast_typedef.h" +#include "ast_array.h" +#include "ast_sequence.h" +#include "ast_predefined_type.h" +#include "ast_string.h" +#include "ast_constant.h" +#include "ast_param_holder.h" +#include "ast_template_module.h" + +#include "utl_identifier.h" +#include "utl_exprlist.h" +#include "nr_extern.h" + +ast_visitor_reifying::ast_visitor_reifying ( + ast_visitor_context *ctx) + : ast_visitor (), + ctx_ (ctx), + reified_node_ (0) +{ +} + +ast_visitor_reifying::~ast_visitor_reifying (void) +{ +} + +AST_Decl * +ast_visitor_reifying::reified_node (void) const +{ + return this->reified_node_; +} + +int ast_visitor_reifying::visit_decl (AST_Decl *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_scope (UTL_Scope *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_type (AST_Type *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_module (AST_Module *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_interface_fwd (AST_InterfaceFwd *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_valuebox (AST_ValueBox *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_valuetype_fwd (AST_ValueTypeFwd *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_eventtype_fwd (AST_EventTypeFwd *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_component_fwd (AST_ComponentFwd *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_template_module (AST_Template_Module *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_template_module_inst (AST_Template_Module_Inst *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_template_module_ref (AST_Template_Module_Ref *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_porttype (AST_PortType *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_provides (AST_Provides *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_uses (AST_Uses *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_publishes (AST_Publishes *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_emits (AST_Emits *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_consumes (AST_Consumes *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_extended_port (AST_Extended_Port *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_mirror_port (AST_Mirror_Port *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_connector (AST_Connector *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_home (AST_Home *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_factory (AST_Factory *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_structure (AST_Structure *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_structure_fwd (AST_StructureFwd *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_expression (AST_Expression *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_enum (AST_Enum *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_operation (AST_Operation *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_field (AST_Field *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_argument (AST_Argument *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_attribute (AST_Attribute *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_union (AST_Union *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_union_fwd (AST_UnionFwd *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_union_branch (AST_UnionBranch *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_union_label (AST_UnionLabel *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_enum_val (AST_EnumVal *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_root (AST_Root *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_native (AST_Native *) +{ + return 0; +} + +int +ast_visitor_reifying::visit_interface (AST_Interface *node) +{ + UTL_ScopedName *tmpl_tail = + this->template_module_rel_name (node); + + if (tmpl_tail != 0) + { + AST_Decl *d = + idl_global->scopes ().top ()->lookup_by_name ( + tmpl_tail, + true); + + this->reified_node_ = d; + } + else + { + this->reified_node_ = node; + } + + return 0; +} + +int +ast_visitor_reifying::visit_valuetype (AST_ValueType *node) +{ + this->reified_node_ = node; + return 0; +} + +int +ast_visitor_reifying::visit_eventtype (AST_EventType *node) +{ + this->reified_node_ = node; + return 0; +} + +int +ast_visitor_reifying::visit_component (AST_Component *node) +{ + this->reified_node_ = node; + return 0; +} + +int +ast_visitor_reifying::visit_exception (AST_Exception *node) +{ + this->reified_node_ = node; + return 0; +} + +int +ast_visitor_reifying::visit_typedef (AST_Typedef *node) +{ + this->reified_node_ = node; + return 0; +} + +int +ast_visitor_reifying::visit_array (AST_Array *node) +{ + AST_Type *bt = node->base_type (); + + if (bt->ast_accept (this) != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ast_visitor_reifying::") + ACE_TEXT ("visit_array - ") + ACE_TEXT ("visit of base type failed\n")), + -1); + } + + bt = AST_Type::narrow_from_decl (this->reified_node_); + + AST_Expression **dims = node->dims (); + AST_Expression *v = 0; + UTL_ExprList *v_list = 0; + + for (ACE_CDR::ULong i = 0; i < node->n_dims (); ++i) + { + AST_Param_Holder *ph = dims[i]->param_holder (); + + if (ph != 0) + { + if (this->visit_param_holder (ph) != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ast_visitor_reifying::") + ACE_TEXT ("visit_array - ") + ACE_TEXT ("visit_param_holder() ") + ACE_TEXT ("failed\n")), + -1); + } + + AST_Constant *c = + AST_Constant::narrow_from_decl (this->reified_node_); + + ACE_NEW_RETURN (v, + AST_Expression (c->constant_value (), + AST_Expression::EV_ulong), + -1); + } + else + { + ACE_NEW_RETURN (v, + AST_Expression (dims[i], + AST_Expression::EV_ulong), + -1); + } + + UTL_ExprList *el = 0; + ACE_NEW_RETURN (el, + UTL_ExprList (v, 0), + -1); + + if (v_list == 0) + { + v_list = el; + } + else + { + v_list->nconc (el); + } + } + + UTL_ScopedName sn (node->name ()->last_component ()->copy (), + 0); + + AST_Array *arr = + idl_global->gen ()->create_array (&sn, + node->n_dims (), + v_list, + false, + false); + + // No need to add this new node to any scope - it's anonymous + // and owned by the node that references it. + + sn.destroy (); + v_list->destroy (); + delete v_list; + v_list = 0; + + arr->set_base_type (bt); + this->reified_node_ = arr; + + return 0; +} + +int +ast_visitor_reifying::visit_sequence (AST_Sequence *node) +{ + AST_Type *bt = node->base_type (); + + if (bt->ast_accept (this) != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ast_visitor_reifying::") + ACE_TEXT ("visit_sequence - ") + ACE_TEXT ("visit of base type failed\n")), + -1); + } + + bt = AST_Type::narrow_from_decl (this->reified_node_); + + AST_Expression *v = node->max_size (); + AST_Param_Holder *ph = v->param_holder (); + + if (ph != 0) + { + if (this->visit_param_holder (ph) != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ast_visitor_reifying::") + ACE_TEXT ("visit_sequence - ") + ACE_TEXT ("visit_param_holder() ") + ACE_TEXT ("failed\n")), + -1); + } + + AST_Constant *c = + AST_Constant::narrow_from_decl (this->reified_node_); + + v = c->constant_value (); + } + + AST_Expression *bound = + idl_global->gen ()->create_expr (v, + AST_Expression::EV_ulong); + Identifier id ("sequence"); + UTL_ScopedName sn (&id, 0); + + this->reified_node_ = + idl_global->gen ()->create_sequence (bound, + bt, + &sn, + false, + false); + + // No need to add this new node to any scope - it's anonymous + // and owned by the node that references it. + + return 0; +} + +int +ast_visitor_reifying::visit_predefined_type (AST_PredefinedType *node) +{ + this->reified_node_ = node; + return 0; +} + +int +ast_visitor_reifying::visit_string (AST_String *node) +{ + this->reified_node_ = node; + return 0; +} + +int +ast_visitor_reifying::visit_constant (AST_Constant *node) +{ + // AFAICT, this is called only on the member constant of a param + // holder, in which case nothing further is needed. + this->reified_node_ = node; + return 0; +} + +int +ast_visitor_reifying::visit_param_holder (AST_Param_Holder *node) +{ + size_t i = 0; + FE_Utils::T_ARGLIST *t_args = + this->ctx_->template_args (); + + for (FE_Utils::T_PARAMLIST_INFO::ITERATOR iter ( + *this->ctx_->template_params ()); + !iter.done (); + iter.advance (), ++i) + { + FE_Utils::T_Param_Info *item = 0; + iter.next (item); + + if (item == node->info ()) + { + AST_Decl **ret_ptr = 0; + + if (t_args->get (ret_ptr, i) == 0) + { + AST_Decl *candidate = *ret_ptr; + + return candidate->ast_accept (this); + } + else + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ast_visitor_reifying::") + ACE_TEXT ("visit_param_holder() - access of ") + ACE_TEXT ("current template arglist failed - ") + ACE_TEXT ("param=%C scope=%C index=%d\n"), + item->name_.c_str (), + ScopeAsDecl (idl_global->scopes ().top ())->full_name (), + i), + -1); + } + } + } + + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ast_visitor_reifying::") + ACE_TEXT ("visit_param_holder() - no match for ") + ACE_TEXT ("template param %C in %C\n"), + node->info ()->name_.c_str (), + ScopeAsDecl (idl_global->scopes ().top ())->full_name ()), + -1); +} + +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 idl_global->string_to_scoped_name (tail.c_str ()); + } + + tmp = ScopeAsDecl (tmp->defined_in ()); + } + + return 0; +}
\ No newline at end of file diff --git a/modules/TAO/TAO_IDL/ast/ast_visitor_tmpl_module_inst.cpp b/modules/TAO/TAO_IDL/ast/ast_visitor_tmpl_module_inst.cpp new file mode 100644 index 00000000000..5e52e5ed2d7 --- /dev/null +++ b/modules/TAO/TAO_IDL/ast/ast_visitor_tmpl_module_inst.cpp @@ -0,0 +1,869 @@ +/** + * @file ast_visitor_tmpl_module_inst.cpp + * + * $Id$ + * + * @author Jeff Parsons + */ +//============================================================================= + +#include "ast_visitor_tmpl_module_inst.h" +#include "ast_visitor_reifying.h" +#include "ast_visitor_context.h" +#include "ast_generator.h" + +#include "ast_root.h" +#include "ast_module.h" +#include "ast_template_module.h" +#include "ast_template_module_inst.h" +#include "ast_eventtype.h" +#include "ast_interface.h" +#include "ast_attribute.h" +#include "ast_operation.h" +#include "ast_argument.h" +#include "ast_typedef.h" +#include "ast_constant.h" +#include "ast_structure.h" +#include "ast_factory.h" +#include "ast_param_holder.h" +#include "ast_expression.h" + +#include "ast_param_holder.h" + +#include "utl_namelist.h" +#include "utl_identifier.h" +#include "utl_exceptlist.h" + +#include "fe_interface_header.h" +#include "fe_obv_header.h" + +#include "nr_extern.h" + +ast_visitor_tmpl_module_inst::ast_visitor_tmpl_module_inst ( + ast_visitor_context *ctx) + : ast_visitor (), + ctx_ (ctx), + for_eventtype_ (false) +{ +} + +ast_visitor_tmpl_module_inst::~ast_visitor_tmpl_module_inst (void) +{ +} + +int ast_visitor_tmpl_module_inst::visit_decl (AST_Decl *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_scope (UTL_Scope *node) +{ + for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls); + !si.is_done (); + si.next ()) + { + AST_Decl *d = si.item (); + + if (d == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ast_visitor_tmpl_module_inst::") + ACE_TEXT ("visit_scope - ") + ACE_TEXT ("bad node in this scope\n")), + -1); + } + + // Send the visitor. + if (d == 0 || d->ast_accept (this) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ast_visitor_tmpl_module_inst::") + ACE_TEXT ("visit_scope - ") + ACE_TEXT ("codegen for scope failed\n")), + -1); + } + } + + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_type (AST_Type *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_interface_fwd (AST_InterfaceFwd *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_valuebox (AST_ValueBox *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_valuetype_fwd (AST_ValueTypeFwd *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_eventtype_fwd (AST_EventTypeFwd *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_component_fwd (AST_ComponentFwd *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_template_module_ref (AST_Template_Module_Ref *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_porttype (AST_PortType *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_provides (AST_Provides *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_uses (AST_Uses *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_publishes (AST_Publishes *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_emits (AST_Emits *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_consumes (AST_Consumes *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_extended_port (AST_Extended_Port *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_mirror_port (AST_Mirror_Port *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_connector (AST_Connector *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_home (AST_Home *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_structure_fwd (AST_StructureFwd *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_expression (AST_Expression *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_enum (AST_Enum *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_union (AST_Union *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_union_fwd (AST_UnionFwd *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_union_branch (AST_UnionBranch *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_union_label (AST_UnionLabel *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_enum_val (AST_EnumVal *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_param_holder (AST_Param_Holder *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_root (AST_Root *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_native (AST_Native *) +{ + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_module (AST_Module *node) +{ + // We can conveniently check this member's value to tell + // if we are (at some level )processing a template module + // instantiation. + // If so, we need to create a new module on the AST. + // When processing of the instantiation is done, the member + // is reset to 0. + bool in_template_module = + this->ctx_->template_args () != 0; + + AST_Module *added_module = 0; + + // If we are traversing a template module as a result of its + // instantiation, we want to create a corresponding module + // in the instantiated module (at the top of the scope stack), + // and push it on the scope stack. Otherwise, we just push + // the module we are visiting. + if (in_template_module) + { + added_module = + idl_global->gen ()->create_module (idl_global->scopes ().top (), + node->name ()); + + idl_global->scopes ().top ()->add_to_scope (added_module); + } + + idl_global->scopes ().push ( + in_template_module ? added_module : node); + + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ast_visitor_tmpl_module_inst::") + ACE_TEXT ("visit_module - ") + ACE_TEXT ("visit scope failed\n")), + -1); + } + + // Restore scope stack. + idl_global->scopes ().pop (); + + return 0; +} + +// Not called from ast_template_module::accept() but from +// visit_template_module_inst() in this visitor. +int +ast_visitor_tmpl_module_inst::visit_template_module ( + AST_Template_Module *node) +{ + this->ctx_->template_params (node->template_params ()); + + if (this->visit_scope (node) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ast_visitor_tmpl_module_inst::") + ACE_TEXT ("visit_template_module - ") + ACE_TEXT ("visit scope failed\n")), + -1); + } + + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_template_module_inst ( + AST_Template_Module_Inst *node) +{ + this->ctx_->template_args (node->template_args ()); + + AST_Module *instance = + idl_global->gen ()->create_module (idl_global->scopes ().top (), + node->name ()); + + // Add the new module to the scope containing the template + // module instantiation. + idl_global->scopes ().top ()->add_to_scope (instance); + + // Update our scope management. + idl_global->scopes ().push (instance); + + AST_Template_Module *tm = node->ref (); + + if (this->visit_template_module (tm) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ast_visitor_tmpl_module_inst::") + ACE_TEXT ("visit_template_module_inst - ") + ACE_TEXT ("visit_template_module failed\n")), + -1); + } + + // By checking this member for a non-zero value, we can tell if + // we are processing an instantiated template module or not. We + // need to know this, for example while visiting an IDL module, + // to decide whether to create an implied IDL module or just + // visit its scope. + this->ctx_->template_args (0); + + // Restore the scope stack. + idl_global->scopes ().pop (); + + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_eventtype (AST_EventType *node) +{ + this->for_eventtype_ = true; + return this->visit_valuetype (node); +} + +int +ast_visitor_tmpl_module_inst::visit_valuetype (AST_ValueType *node) +{ + if (this->ctx_->template_args () == 0) + { + return 0; + } + + UTL_NameList *parent_names = + this->create_name_list (node->inherits (), + node->n_inherits ()); + + UTL_NameList *supports_names = + this->create_name_list (node->supports (), + node->n_supports ()); + + Identifier *node_id = 0; + ACE_NEW_RETURN (node_id, + Identifier (node->local_name ()->get_string ()), + -1); + + UTL_ScopedName *local_name = 0; + ACE_NEW_RETURN (local_name, + UTL_ScopedName (node_id, 0), + -1); + + AST_ValueType *added_vtype = 0; + + FE_OBVHeader header (local_name, + parent_names, + supports_names, + (parent_names != 0 + ? parent_names->truncatable () + : false), + this->for_eventtype_); + + if (this->for_eventtype_) + { + added_vtype = + idl_global->gen ()->create_eventtype (header.name (), + header.inherits (), + header.n_inherits (), + header.inherits_concrete (), + header.inherits_flat (), + header.n_inherits_flat (), + header.supports (), + header.n_supports (), + header.supports_concrete (), + false, + header.truncatable (), + false); + } + else + { + added_vtype = + idl_global->gen ()->create_valuetype (header.name (), + header.inherits (), + header.n_inherits (), + header.inherits_concrete (), + header.inherits_flat (), + header.n_inherits_flat (), + header.supports (), + header.n_supports (), + header.supports_concrete (), + false, + header.truncatable (), + false); + } + + parent_names->destroy (); + delete parent_names; + parent_names = 0; + + supports_names->destroy (); + delete supports_names; + supports_names = 0; + + idl_global->scopes ().top ()->add_to_scope (added_vtype); + + // Update the scope management. + idl_global->scopes ().push (added_vtype); + + if (this->visit_scope (node) != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ast_visitor_tmpl_module_inst::") + ACE_TEXT ("visit_valuetype - ") + ACE_TEXT ("visit_scope failed\n")), + -1); + } + + // Through with this scope. + idl_global->scopes ().pop (); + + // Reset the flag. + this->for_eventtype_ = false; + + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_interface (AST_Interface *node) +{ + if (this->ctx_->template_args () == 0) + { + return 0; + } + + UTL_NameList *parent_names = + this->create_name_list (node->inherits (), + node->n_inherits ()); + + Identifier *node_id = 0; + ACE_NEW_RETURN (node_id, + Identifier (node->local_name ()->get_string ()), + -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); + + AST_Interface *added_iface = + idl_global->gen ()->create_interface (header.name (), + header.inherits (), + header.n_inherits (), + header.inherits_flat (), + header.n_inherits_flat (), + header.is_local (), + header.is_abstract ()); + + parent_names->destroy (); + delete parent_names; + parent_names = 0; + + idl_global->scopes ().top ()->add_to_scope (added_iface); + + // Update the scope stack. + idl_global->scopes ().push (added_iface); + + if (this->visit_scope (node) != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ast_visitor_tmpl_module_inst::") + ACE_TEXT ("visit_interface - ") + ACE_TEXT ("visit_scope failed\n")), + -1); + } + + // Through with this scope. + idl_global->scopes ().pop (); + + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_attribute (AST_Attribute *node) +{ + AST_Type *ft = + AST_Type::narrow_from_decl ( + this->reify_type (node->field_type ())); + + AST_Attribute *added_attr = + idl_global->gen ()->create_attribute (node->readonly (), + ft, + node->name (), + node->is_local (), + node->is_abstract ()); + + idl_global->scopes ().top ()->add_to_scope (added_attr); + + // 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 +ast_visitor_tmpl_module_inst::visit_operation (AST_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); + + AST_Operation *added_op = + idl_global->gen ()->create_operation (rt, + node->flags (), + &sn, + node->is_local (), + node->is_abstract ()); + + idl_global->scopes ().top ()->add_to_scope (added_op); + + // Update the scope stack. + idl_global->scopes ().push (added_op); + + if (this->visit_scope (node) != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ast_visitor_tmpl_module_inst::") + ACE_TEXT ("visit_operation - ") + ACE_TEXT ("visit_scope failed\n")), + -1); + } + + // Through with this scope. + idl_global->scopes ().pop (); + + UTL_ExceptList *new_ex = + this->reify_exception_list (node->exceptions ()); + + added_op->be_add_exceptions (new_ex); + + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_argument (AST_Argument *node) +{ + AST_Type *t = + AST_Type::narrow_from_decl ( + this->reify_type (node->field_type ())); + + AST_Argument *added_arg = + idl_global->gen ()->create_argument (node->direction (), + t, + node->name ()); + + idl_global->scopes ().top ()->add_to_scope (added_arg); + + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_typedef (AST_Typedef *node) +{ + if (this->ctx_->template_args () == 0) + { + return 0; + } + + AST_Type *bt = + AST_Type::narrow_from_decl ( + this->reify_type (node->base_type ())); + + AST_Typedef *added_td = + idl_global->gen ()->create_typedef (bt, + node->name (), + false, + false); + + idl_global->scopes ().top ()->add_to_scope (added_td); + + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_constant (AST_Constant *node) +{ + if (this->ctx_->template_args () == 0) + { + return 0; + } + + AST_Param_Holder *ph = + node->constant_value ()->param_holder (); + + AST_Expression *v = 0; + AST_Expression::ExprType et = AST_Expression::EV_none; + + if (ph != 0) + { + ast_visitor_reifying rv (this->ctx_); + + if (rv.visit_param_holder (ph) != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ast_visitor_tmpl_module_inst::") + ACE_TEXT ("visit_constant - ") + ACE_TEXT ("reification of param ") + ACE_TEXT ("holder failed\n")), + -1); + } + + AST_Constant *c = + AST_Constant::narrow_from_decl (rv.reified_node ()); + + v = c->constant_value (); + et = c->et (); + } + else + { + v = node->constant_value (); + et = node->et (); + } + + AST_Expression *new_v = + idl_global->gen ()->create_expr (v, et); + + AST_Constant *added_const = + idl_global->gen ()->create_constant (et, + new_v, + node->name ()); + + idl_global->scopes ().top ()->add_to_scope (added_const); + + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_structure (AST_Structure *node) +{ + if (this->ctx_->template_args () == 0) + { + return 0; + } + + UTL_ScopedName sn (node->name ()->last_component (), 0); + + AST_Structure *added_struct = + idl_global->gen ()->create_structure (&sn, + node->is_local (), + node->is_abstract ()); + + idl_global->scopes ().top ()->add_to_scope (added_struct); + + // Update our scope stack. + idl_global->scopes ().push (added_struct); + + if (this->visit_scope (node) != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ast_visitor_tmpl_module_inst::") + ACE_TEXT ("visit_structure - ") + ACE_TEXT ("visit_scope() failed\n")), + -1); + } + + // Through with this scope. + idl_global->scopes ().pop (); + + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_field (AST_Field *node) +{ + AST_Type *t = + AST_Type::narrow_from_decl ( + this->reify_type (node->field_type ())); + + AST_Field *added_field = + idl_global->gen ()->create_field (t, + node->name (), + node->visibility ()); + + idl_global->scopes ().top ()->add_to_scope (added_field); + + return 0; +} + +int +ast_visitor_tmpl_module_inst::visit_factory (AST_Factory *node) +{ + Identifier id (node->local_name ()->get_string ()); + UTL_ScopedName sn (&id, 0); + + AST_Factory *added_factory = + idl_global->gen ()->create_factory (&sn); + + idl_global->scopes ().top ()->add_to_scope (added_factory); + + // Update the scope stack. + idl_global->scopes ().push (added_factory); + + if (this->visit_scope (node) != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ast_visitor_tmpl_module_inst::") + ACE_TEXT ("visit_factory - ") + ACE_TEXT ("visit_scope() failed\n")), + -1); + } + + // Through with this scope. + idl_global->scopes ().pop (); + + UTL_ExceptList *reified_exceps = + this->reify_exception_list (node->exceptions ()); + + added_factory->be_add_exceptions (reified_exceps); + + return 0; +} + +AST_Decl * +ast_visitor_tmpl_module_inst::reify_type (AST_Decl *d) +{ + ast_visitor_reifying rv (this->ctx_); + + if (d->ast_accept (&rv) != 0) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("ast_visitor_tmpl_module_inst::") + ACE_TEXT ("reify_type() - reifying ") + ACE_TEXT ("visitor failed on %C\n"), + d->full_name ())); + + return 0; + } + + return rv.reified_node (); +} + +UTL_ExceptList * +ast_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; +} + +UTL_NameList * +ast_visitor_tmpl_module_inst::create_name_list (AST_Type **list, + long length) +{ + UTL_NameList *retval = 0; + + for (long i = 0; i < length; ++i) + { + AST_Type *item = + AST_Type::narrow_from_decl (this->reify_type (list[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 *name_item = 0; + ACE_NEW_RETURN (name_item, + UTL_NameList (item->name ()->copy (), 0), + 0); + + if (retval == 0) + { + retval = name_item; + } + else + { + retval->nconc (name_item); + } + } + + return retval; +} diff --git a/modules/TAO/TAO_IDL/be/be_factory.cpp b/modules/TAO/TAO_IDL/be/be_factory.cpp index f04f4fc2cc2..13653d72dba 100644 --- a/modules/TAO/TAO_IDL/be/be_factory.cpp +++ b/modules/TAO/TAO_IDL/be/be_factory.cpp @@ -73,23 +73,6 @@ be_factory::accept (be_visitor *visitor) return visitor->visit_factory (this); } -UTL_ExceptList * -be_factory::be_add_exceptions (UTL_ExceptList *t) -{ - if (this->pd_exceptions != 0) - { - idl_global->err ()->error1 (UTL_Error::EIDL_ILLEGAL_RAISES, - this); - } - else - { - this->pd_exceptions = t; - this->pd_n_exceptions = (t == 0 ? 0 : t->length ()); - } - - return this->pd_exceptions; -} - AST_Argument * be_factory::be_add_argument (AST_Argument *arg) { diff --git a/modules/TAO/TAO_IDL/be/be_generator.cpp b/modules/TAO/TAO_IDL/be/be_generator.cpp index 66417ad65c2..9d6fb99f38d 100644 --- a/modules/TAO/TAO_IDL/be/be_generator.cpp +++ b/modules/TAO/TAO_IDL/be/be_generator.cpp @@ -158,22 +158,23 @@ be_generator::create_module (UTL_Scope *s, be_module (n), 0); + AST_Module *m = 0; // Check for another module of the same name in this scope. for (UTL_ScopeActiveIterator iter (s, UTL_Scope::IK_decls); !iter.is_done (); iter.next ()) { - AST_Decl *d = iter.item (); + // Can't just check node type here, since it could be a + // template module or template module instantiation. + m = AST_Module::narrow_from_decl (iter.item ()); - if (d->node_type () == AST_Decl::NT_module) + if (m != 0) { // Does it have the same name as the one we're // supposed to create. - if (d->local_name ()->compare (n->last_component ())) + if (m->local_name ()->compare (n->last_component ())) { - AST_Module *m = AST_Module::narrow_from_decl (d); - // Get m's previous_ member, plus all it's decls, // into the new modules's previous_ member. retval->add_to_previous (m); @@ -190,21 +191,26 @@ be_generator::create_module (UTL_Scope *s, if (nt == AST_Decl::NT_module || nt == AST_Decl::NT_root) { - AST_Module *m = AST_Module::narrow_from_decl (d); - - // AST_Module::previous_ is a set, so it contains each - // entry only once, but previous_ will contain the decls - // from all previous openings. See comment in - // AST_Module::add_to_previous() body. - d = m->look_in_previous (n->last_component ()); + // Also check this to week out a template module or its + // instantiation. + m = AST_Module::narrow_from_decl (d); - if (d != 0) + if (m != 0) { - if (d->node_type () == AST_Decl::NT_module) + // AST_Module::previous_ is a set, so it contains each + // entry only once, but previous_ will contain the decls + // from all previous openings. See comment in + // AST_Module::add_to_previous() body. + d = m->look_in_previous (n->last_component ()); + + if (d != 0) { - m = AST_Module::narrow_from_decl (d); + if (d->node_type () == AST_Decl::NT_module) + { + m = AST_Module::narrow_from_decl (d); - retval->add_to_previous (m); + retval->add_to_previous (m); + } } } } diff --git a/modules/TAO/TAO_IDL/be/be_operation.cpp b/modules/TAO/TAO_IDL/be/be_operation.cpp index ab99fea733d..72547e47501 100644 --- a/modules/TAO/TAO_IDL/be/be_operation.cpp +++ b/modules/TAO/TAO_IDL/be/be_operation.cpp @@ -109,22 +109,6 @@ be_operation::accept (be_visitor *visitor) return visitor->visit_operation (this); } -UTL_ExceptList * -be_operation::be_add_exceptions (UTL_ExceptList *t) -{ - if (this->pd_exceptions != 0) - { - idl_global->err ()->error1 (UTL_Error::EIDL_ILLEGAL_RAISES, - this); - } - else - { - this->pd_exceptions = t; - } - - return this->pd_exceptions; -} - AST_Argument * be_operation::be_add_argument (AST_Argument *arg) { diff --git a/modules/TAO/TAO_IDL/be/be_produce.cpp b/modules/TAO/TAO_IDL/be/be_produce.cpp index 0f22dcfdbbd..4300a53bd8e 100644 --- a/modules/TAO/TAO_IDL/be/be_produce.cpp +++ b/modules/TAO/TAO_IDL/be/be_produce.cpp @@ -68,7 +68,6 @@ trademarks or registered trademarks of Sun Microsystems, Inc. #include "be_visitor_ami_pre_proc.h" #include "be_visitor_amh_pre_proc.h" #include "be_visitor_ccm_pre_proc.h" -#include "be_visitor_tmpl_module_inst.h" #include "be_visitor_context.h" #include "be_root.h" #include "be_extern.h" @@ -119,11 +118,6 @@ BE_produce (void) if (!idl_global->ignore_idl3 ()) { - // This visitor needs to make its pass before the CCM - // processing visitor. - be_visitor_tmpl_module_inst tmpl_mod_inst_visitor (&ctx); - BE_visit_root (tmpl_mod_inst_visitor, "template module procdessing"); - be_visitor_ccm_pre_proc ccm_preproc_visitor (&ctx); BE_visit_root (ccm_preproc_visitor, "CCM preprocessing"); } diff --git a/modules/TAO/TAO_IDL/be/be_scope.cpp b/modules/TAO/TAO_IDL/be/be_scope.cpp index 54081fe8150..91f03b92adb 100644 --- a/modules/TAO/TAO_IDL/be/be_scope.cpp +++ b/modules/TAO/TAO_IDL/be/be_scope.cpp @@ -42,12 +42,6 @@ be_scope::be_add_field (AST_Field *f) return this->fe_add_field (f); } -UTL_ExceptList * -be_scope::be_add_exceptions (UTL_ExceptList *t) -{ - return 0; -} - AST_Argument * be_scope::be_add_argument (AST_Argument *arg) { diff --git a/modules/TAO/TAO_IDL/be/be_visitor.cpp b/modules/TAO/TAO_IDL/be/be_visitor.cpp index a88a7c58928..264d86a8980 100644 --- a/modules/TAO/TAO_IDL/be/be_visitor.cpp +++ b/modules/TAO/TAO_IDL/be/be_visitor.cpp @@ -22,6 +22,7 @@ // ============================================================================ #include "be_visitor.h" + #include "ace/config-all.h" be_visitor::be_visitor (void) diff --git a/modules/TAO/TAO_IDL/be/be_visitor_context.cpp b/modules/TAO/TAO_IDL/be/be_visitor_context.cpp index 476c62780d4..b7b41d1781a 100644 --- a/modules/TAO/TAO_IDL/be/be_visitor_context.cpp +++ b/modules/TAO/TAO_IDL/be/be_visitor_context.cpp @@ -5,7 +5,7 @@ // ============================================================================ // // = LIBRARY -// TAO IDL +// TAO_IDL_FE // // = FILENAME // be_visitor_context.cpp @@ -43,7 +43,8 @@ #include "be_visitor_context.h" be_visitor_context::be_visitor_context (void) - : state_ (TAO_CodeGen::TAO_INITIAL), + : ast_visitor_context (), + state_ (TAO_CodeGen::TAO_INITIAL), sub_state_ (TAO_CodeGen::TAO_SUB_STATE_UNKNOWN), os_ (0), scope_ (0), @@ -53,14 +54,13 @@ be_visitor_context::be_visitor_context (void) attr_ (0), exception_ (0), comma_ (0), - interface_ (0), - template_params_ (0), - template_args_ (0) + interface_ (0) { } be_visitor_context::be_visitor_context (const be_visitor_context &ctx) - : state_ (ctx.state_), + : ast_visitor_context (ctx), + state_ (ctx.state_), sub_state_ (ctx.sub_state_), os_ (ctx.os_), scope_ (ctx.scope_), @@ -70,9 +70,7 @@ be_visitor_context::be_visitor_context (const be_visitor_context &ctx) attr_ (ctx.attr_), exception_ (ctx.exception_), comma_ (ctx.comma_), - interface_ (ctx.interface_), - template_params_ (ctx.template_params_), - template_args_ (ctx.template_args_) + interface_ (ctx.interface_) { } @@ -98,7 +96,7 @@ be_visitor_context::operator= (const be_visitor_context &ctx) be_visitor_context::~be_visitor_context (void) { - // we do not own anything + // We do not own anything. } //= helpers @@ -253,30 +251,6 @@ be_visitor_context::interface (void) const return this->interface_; } -FE_Utils::T_PARAMLIST_INFO * -be_visitor_context::template_params (void) const -{ - return this->template_params_; -} - -void -be_visitor_context::template_params (FE_Utils::T_PARAMLIST_INFO *params) -{ - this->template_params_ = params; -} - -FE_Utils::T_ARGLIST * -be_visitor_context::template_args (void) const -{ - return this->template_args_; -} - -void -be_visitor_context::template_args (FE_Utils::T_ARGLIST *args) -{ - this->template_args_ = args; -} - // **************************************************************** be_argument * diff --git a/modules/TAO/TAO_IDL/be/be_visitor_interface/interface_ex_idl.cpp b/modules/TAO/TAO_IDL/be/be_visitor_interface/interface_ex_idl.cpp index 7b43c9dc617..5aecbfdd134 100644 --- a/modules/TAO/TAO_IDL/be/be_visitor_interface/interface_ex_idl.cpp +++ b/modules/TAO/TAO_IDL/be/be_visitor_interface/interface_ex_idl.cpp @@ -21,10 +21,6 @@ // Interface visitor for CIAO executor IDL. // ************************************************************ -ACE_RCSID (be_visitor_interface, - interface_ex_idl, - "$Id$") - be_visitor_interface_ex_idl::be_visitor_interface_ex_idl ( be_visitor_context *ctx) : be_visitor_interface (ctx) diff --git a/modules/TAO/TAO_IDL/be/be_visitor_module.cpp b/modules/TAO/TAO_IDL/be/be_visitor_module.cpp index c36fb8a088f..463e6a6c506 100644 --- a/modules/TAO/TAO_IDL/be/be_visitor_module.cpp +++ b/modules/TAO/TAO_IDL/be/be_visitor_module.cpp @@ -70,6 +70,3 @@ #include "be_visitor_module/cdr_op.cpp" #include "be_visitor_module/serializer_op.cpp" -ACE_RCSID (be, - be_visitor_module, - "$Id$") diff --git a/modules/TAO/TAO_IDL/be/be_visitor_scope.cpp b/modules/TAO/TAO_IDL/be/be_visitor_scope.cpp index 8449e9da424..1842b5f9b63 100644 --- a/modules/TAO/TAO_IDL/be/be_visitor_scope.cpp +++ b/modules/TAO/TAO_IDL/be/be_visitor_scope.cpp @@ -25,10 +25,6 @@ #include "be_visitor_context.h" #include "ace/Log_Msg.h" -ACE_RCSID (be, - be_visitor_scope, - "$Id$") - // ****************************************************** // Generic visitor for a scope. // All elements that give rise to a scope inherit from diff --git a/modules/TAO/TAO_IDL/be_include/be_factory.h b/modules/TAO/TAO_IDL/be_include/be_factory.h index dfbfd63d8b5..08c9b61e7ee 100644 --- a/modules/TAO/TAO_IDL/be_include/be_factory.h +++ b/modules/TAO/TAO_IDL/be_include/be_factory.h @@ -51,9 +51,6 @@ public: // Visiting. virtual int accept (be_visitor *visitor); - // Method to add exceptions - virtual UTL_ExceptList *be_add_exceptions (UTL_ExceptList *t); - // Add an argument to the scope. virtual AST_Argument *be_add_argument (AST_Argument *arg); diff --git a/modules/TAO/TAO_IDL/be_include/be_operation.h b/modules/TAO/TAO_IDL/be_include/be_operation.h index 02e1baf46dd..84bc54e93c5 100644 --- a/modules/TAO/TAO_IDL/be_include/be_operation.h +++ b/modules/TAO/TAO_IDL/be_include/be_operation.h @@ -56,9 +56,6 @@ public: // Visiting. virtual int accept (be_visitor *visitor); - // Method to add exceptions - virtual UTL_ExceptList *be_add_exceptions (UTL_ExceptList *t); - // Add an argument to the scope. virtual AST_Argument *be_add_argument (AST_Argument *arg); diff --git a/modules/TAO/TAO_IDL/be_include/be_scope.h b/modules/TAO/TAO_IDL/be_include/be_scope.h index 5f8900cc7e4..d3df558666d 100644 --- a/modules/TAO/TAO_IDL/be_include/be_scope.h +++ b/modules/TAO/TAO_IDL/be_include/be_scope.h @@ -50,7 +50,6 @@ public: AST_Field *be_add_field (AST_Field *f); // To access the protected base class method fe_add_field. - virtual UTL_ExceptList *be_add_exceptions (UTL_ExceptList *t); virtual AST_Argument *be_add_argument (AST_Argument *arg); // Overridden in be_operation and be_factory. diff --git a/modules/TAO/TAO_IDL/be_include/be_visitor_context.h b/modules/TAO/TAO_IDL/be_include/be_visitor_context.h index 476f273aa5b..8ecc5843691 100644 --- a/modules/TAO/TAO_IDL/be_include/be_visitor_context.h +++ b/modules/TAO/TAO_IDL/be_include/be_visitor_context.h @@ -6,7 +6,7 @@ // ============================================================================ // // = LIBRARY -// TAO IDL +// TAO_IDL_BE // // = FILENAME // be_visitor_context.h @@ -26,10 +26,12 @@ #ifndef TAO_BE_VISITOR_CONTEXT_H #define TAO_BE_VISITOR_CONTEXT_H -#include "be_codegen.h" +#include "ast_visitor_context.h" #include "fe_utils.h" +#include "be_codegen.h" + class TAO_OutStream; class be_decl; class be_typedef; @@ -62,7 +64,7 @@ class be_union_branch; # undef interface #endif /* interface */ -class be_visitor_context +class be_visitor_context : public ast_visitor_context { public: be_visitor_context (void); @@ -150,14 +152,6 @@ public: // *generating* code, as opposed to the interfaces where the methods // or structures are defined. - // Accessors/mutators for the template-related members. - - FE_Utils::T_PARAMLIST_INFO *template_params (void) const; - void template_params (FE_Utils::T_PARAMLIST_INFO *params); - - FE_Utils::T_ARGLIST *template_args (void) const; - void template_args (FE_Utils::T_ARGLIST *args); - // = helpers // visitors may need the actual type of the node stored in this context. We diff --git a/modules/TAO/TAO_IDL/fe/fe_interface_header.cpp b/modules/TAO/TAO_IDL/fe/fe_interface_header.cpp index d55b0686604..ca6a9ac3a42 100644 --- a/modules/TAO/TAO_IDL/fe/fe_interface_header.cpp +++ b/modules/TAO/TAO_IDL/fe/fe_interface_header.cpp @@ -84,6 +84,8 @@ trademarks or registered trademarks of Sun Microsystems, Inc. #include "global_extern.h" #include "nr_extern.h" +#include "ace/streams.h" + #undef INCREMENT #define INCREMENT 512 @@ -290,6 +292,9 @@ FE_InterfaceHeader::compile_inheritance (UTL_NameList *ifaces, // We will crash if we continue from here. throw Bailout (); } + + item->dump (std::cout); + cout << endl; // Look it up. d = s->lookup_by_name (item, diff --git a/modules/TAO/TAO_IDL/include/ast_factory.h b/modules/TAO/TAO_IDL/include/ast_factory.h index f78f06414d1..f11092b7f3d 100644 --- a/modules/TAO/TAO_IDL/include/ast_factory.h +++ b/modules/TAO/TAO_IDL/include/ast_factory.h @@ -120,6 +120,9 @@ public: // Visiting. virtual int ast_accept (ast_visitor *visitor); + // Method to add exceptions. + UTL_ExceptList *be_add_exceptions (UTL_ExceptList *t); + protected: // Data. diff --git a/modules/TAO/TAO_IDL/include/ast_operation.h b/modules/TAO/TAO_IDL/include/ast_operation.h index d7b0df63f8b..d1aef80a39a 100644 --- a/modules/TAO/TAO_IDL/include/ast_operation.h +++ b/modules/TAO/TAO_IDL/include/ast_operation.h @@ -146,6 +146,9 @@ public: // Visiting. virtual int ast_accept (ast_visitor *visitor); + // Method to add exceptions + UTL_ExceptList *be_add_exceptions (UTL_ExceptList *t); + protected: // Data. diff --git a/modules/TAO/TAO_IDL/include/ast_visitor_context.h b/modules/TAO/TAO_IDL/include/ast_visitor_context.h new file mode 100644 index 00000000000..8b1b995f32f --- /dev/null +++ b/modules/TAO/TAO_IDL/include/ast_visitor_context.h @@ -0,0 +1,54 @@ +// +// $Id$ +// + +/* -*- C++ -*- */ +// ============================================================================ +// +// = LIBRARY +// TAO_IDL_FE +// +// = FILENAME +// ast_visitor_context.h +// +// = DESCRIPTION +// This class serves to provide the necessary context information to the +// visitor as it generates code. This may include the scope inside which the +// code is generated, the output file that is being used, and others. This +// context information will be passed to the abstract/concrete visitor +// factory which in turn will use it to construct the right visitor. +// +// = AUTHOR +// Jeff Parsons & Aniruddha Gokhale +// +// ============================================================================ + +#ifndef AST_VISITOR_CONTEXT_H +#define AST_VISITOR_CONTEXT_H + +#include "fe_utils.h" + +class TAO_IDL_FE_Export ast_visitor_context +{ +public: + ast_visitor_context (void); + + ast_visitor_context (const ast_visitor_context &ctx); + + ~ast_visitor_context (void); + + // Accessors/mutators for template-related storage. + + FE_Utils::T_PARAMLIST_INFO *template_params (void) const; + void template_params (FE_Utils::T_PARAMLIST_INFO *args); + + FE_Utils::T_ARGLIST *template_args (void) const; + void template_args (FE_Utils::T_ARGLIST *args); + +protected: + // Storage for the current template module params and args. + FE_Utils::T_PARAMLIST_INFO *template_params_; + FE_Utils::T_ARGLIST *template_args_; +}; + +#endif /* AST_VISITOR_CONTEXT_H */ diff --git a/modules/TAO/TAO_IDL/include/ast_visitor_reifying.h b/modules/TAO/TAO_IDL/include/ast_visitor_reifying.h new file mode 100644 index 00000000000..449435b4a63 --- /dev/null +++ b/modules/TAO/TAO_IDL/include/ast_visitor_reifying.h @@ -0,0 +1,116 @@ +// +// $Id$ +// + +/* -*- c++ -*- */ +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// ast_visitor_reifying.h +// +// = DESCRIPTION +// This visitor visits an AST_Param_Holder, finds the corresponding +// template argument, looks up or creates the type, and stores +// it for retrieval and use in the template module +// instantiation visitor +// +// = AUTHOR +// Jeff Parsons +// +// ============================================================================ + +#ifndef TAO_AST_VISITOR_REIFYING_H +#define TAO_AST_VISITOR_REIFYING_H + +#include "ast_visitor.h" + +#include "utl_scoped_name.h" + +class AST_Decl; +class AST_Param_Holder; +class ast_visitor_context; + +class ast_visitor_reifying : public ast_visitor +{ + // + // = TITLE + // ast_visitor_reifying + // + // = DESCRIPTION + // Reifies a template argument that has been substituted for + // a template parameter reference. Complete reification may + // include further reification, for example of array + // dimensions, sequence bound or (w)string bound + // for addition to the scope of the template module + // instantiation. + // +public: + ast_visitor_reifying (ast_visitor_context *ctx); + + virtual ~ast_visitor_reifying (void); + + AST_Decl *reified_node (void) const; + + virtual int visit_decl (AST_Decl *d); + virtual int visit_scope (UTL_Scope *node); + virtual int visit_type (AST_Type *node); + virtual int visit_module (AST_Module *node); + virtual int visit_interface_fwd (AST_InterfaceFwd *node); + virtual int visit_valuetype_fwd (AST_ValueTypeFwd *node); + virtual int visit_home (AST_Home *node); + virtual int visit_component_fwd (AST_ComponentFwd *node); + virtual int visit_template_module (AST_Template_Module *node); + virtual int visit_template_module_inst (AST_Template_Module_Inst *node); + virtual int visit_template_module_ref (AST_Template_Module_Ref *node); + virtual int visit_porttype (AST_PortType *node); + virtual int visit_provides (AST_Provides *node); + virtual int visit_uses (AST_Uses *node); + virtual int visit_publishes (AST_Publishes *node); + virtual int visit_emits (AST_Emits *node); + virtual int visit_consumes (AST_Consumes *node); + virtual int visit_extended_port (AST_Extended_Port *node); + virtual int visit_mirror_port (AST_Mirror_Port *node); + virtual int visit_connector (AST_Connector *node); + virtual int visit_eventtype_fwd (AST_EventTypeFwd *node); + virtual int visit_factory (AST_Factory *node); + virtual int visit_structure (AST_Structure *node); + virtual int visit_structure_fwd (AST_StructureFwd *node); + virtual int visit_expression (AST_Expression *node); + virtual int visit_enum (AST_Enum *node); + virtual int visit_operation (AST_Operation *node); + virtual int visit_field (AST_Field *node); + virtual int visit_argument (AST_Argument *node); + virtual int visit_attribute (AST_Attribute *node); + virtual int visit_union (AST_Union *node); + virtual int visit_union_fwd (AST_UnionFwd *node); + virtual int visit_union_branch (AST_UnionBranch *node); + virtual int visit_union_label (AST_UnionLabel *node); + virtual int visit_enum_val (AST_EnumVal *node); + virtual int visit_root (AST_Root *node); + virtual int visit_native (AST_Native *node); + virtual int visit_valuebox (AST_ValueBox *node); + virtual int visit_interface (AST_Interface *node); + virtual int visit_valuetype (AST_ValueType *node); + virtual int visit_eventtype (AST_EventType *node); + virtual int visit_component (AST_Component *node); + virtual int visit_exception (AST_Exception *node); + virtual int visit_typedef (AST_Typedef *node); + virtual int visit_array (AST_Array *node); + virtual int visit_sequence (AST_Sequence *node); + virtual int visit_predefined_type (AST_PredefinedType *node); + virtual int visit_string (AST_String *node); + virtual int visit_constant (AST_Constant *node); + virtual int visit_param_holder (AST_Param_Holder *node); + +private: + UTL_ScopedName *template_module_rel_name (AST_Decl *d); + +private: + ast_visitor_context *ctx_; + AST_Decl *reified_node_; +}; + +#endif // TAO_AST_VISITOR_REIFYING_H
\ No newline at end of file diff --git a/modules/TAO/TAO_IDL/include/ast_visitor_tmpl_module_inst.h b/modules/TAO/TAO_IDL/include/ast_visitor_tmpl_module_inst.h new file mode 100644 index 00000000000..99cc1cfc597 --- /dev/null +++ b/modules/TAO/TAO_IDL/include/ast_visitor_tmpl_module_inst.h @@ -0,0 +1,118 @@ +// +// $Id$ +// + +/* -*- c++ -*- */ +// ============================================================================ +// +// = LIBRARY +// TAO IDL +// +// = FILENAME +// ast_visitor_tmpl_module_inst.h +// +// = DESCRIPTION +// This visitor creates nodes resulting +// from the instantiation of a template module, or from a +// reference to one inside another, and adds these nodes +// to the AST. +// +// = AUTHOR +// Jeff Parsons +// +// ============================================================================ + +#ifndef TAO_AST_VISITOR_TMPL_MODULE_INST_H +#define TAO_AST_VISITOR_TMPL_MODULE_INST_H + +#include "ast_visitor.h" +#include "fe_utils.h" + +class UTL_ExceptList; +class UTL_NameList; +class ast_visitor_context; + +class ast_visitor_tmpl_module_inst : public ast_visitor +{ + // + // = TITLE + // ast_visitor_tmpl_module_inst + // + // = DESCRIPTION + // Adds implied IDL code to the AST related to the + // instantiation or alias of a template module. + // +public: + ast_visitor_tmpl_module_inst (ast_visitor_context *ctx); + + virtual ~ast_visitor_tmpl_module_inst (void); + + virtual int visit_decl (AST_Decl *d); + virtual int visit_scope (UTL_Scope *node); + virtual int visit_type (AST_Type *node); + virtual int visit_interface_fwd (AST_InterfaceFwd *node); + virtual int visit_valuetype_fwd (AST_ValueTypeFwd *node); + virtual int visit_home (AST_Home *node); + virtual int visit_component_fwd (AST_ComponentFwd *node); + virtual int visit_template_module_ref (AST_Template_Module_Ref *node); + virtual int visit_porttype (AST_PortType *node); + virtual int visit_provides (AST_Provides *node); + virtual int visit_uses (AST_Uses *node); + virtual int visit_publishes (AST_Publishes *node); + virtual int visit_emits (AST_Emits *node); + virtual int visit_consumes (AST_Consumes *node); + virtual int visit_extended_port (AST_Extended_Port *node); + virtual int visit_mirror_port (AST_Mirror_Port *node); + virtual int visit_connector (AST_Connector *node); + virtual int visit_eventtype_fwd (AST_EventTypeFwd *node); + virtual int visit_structure_fwd (AST_StructureFwd *node); + virtual int visit_expression (AST_Expression *node); + virtual int visit_enum (AST_Enum *node); + virtual int visit_union (AST_Union *node); + virtual int visit_union_fwd (AST_UnionFwd *node); + virtual int visit_union_branch (AST_UnionBranch *node); + virtual int visit_union_label (AST_UnionLabel *node); + virtual int visit_enum_val (AST_EnumVal *node); + virtual int visit_native (AST_Native *node); + virtual int visit_valuebox (AST_ValueBox *node); + virtual int visit_param_holder (AST_Param_Holder *node); + virtual int visit_root (AST_Root *node); + virtual int visit_module (AST_Module *node); + virtual int visit_template_module (AST_Template_Module *node); + virtual int visit_template_module_inst (AST_Template_Module_Inst *node); + virtual int visit_eventtype (AST_EventType *node); + virtual int visit_valuetype (AST_ValueType *node); + virtual int visit_interface (AST_Interface *node); + virtual int visit_attribute (AST_Attribute *node); + virtual int visit_operation (AST_Operation *node); + virtual int visit_argument (AST_Argument *node); + virtual int visit_typedef (AST_Typedef *node); + virtual int visit_constant (AST_Constant *node); + virtual int visit_structure (AST_Structure *node); + virtual int visit_field (AST_Field *node); + virtual int visit_factory (AST_Factory *node); + +private: + // If arg is a param holder, return the matching template arg, + // otherwise return arg unchanged. If the arg is declared in + // 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); + + // Utility method to create a NameList from a list of inherited + // or supported types that may contain a template param ref. + UTL_NameList *create_name_list (AST_Type **list, long length); + +private: + ast_visitor_context *ctx_; + + // Flag to branch in visit_valuetype() where we create an + // eventtype or a valuetype. + bool for_eventtype_; +}; + +#endif // TAO_AST_VISITOR_TMPL_MODULE_INST_H + diff --git a/modules/TAO/TAO_IDL/util/utl_scope.cpp b/modules/TAO/TAO_IDL/util/utl_scope.cpp index 22b013c284f..a3bd81e459c 100644 --- a/modules/TAO/TAO_IDL/util/utl_scope.cpp +++ b/modules/TAO/TAO_IDL/util/utl_scope.cpp @@ -80,6 +80,7 @@ trademarks or registered trademarks of Sun Microsystems, Inc. #include "ast_porttype.h" #include "ast_template_module.h" #include "ast_template_module_ref.h" +#include "ast_template_module_inst.h" #include "ast_typedef.h" #include "ast_type.h" #include "ast_root.h" @@ -114,10 +115,6 @@ trademarks or registered trademarks of Sun Microsystems, Inc. // FUZZ: disable check_for_streams_include #include "ace/streams.h" -ACE_RCSID (util, - utl_scope, - "$Id$") - #undef INCREMENT #define INCREMENT 64 @@ -1791,7 +1788,7 @@ UTL_Scope::lookup_by_name_local (Identifier *e, { continue; } - + return d; } else |