diff options
author | parsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2010-05-21 23:06:20 +0000 |
---|---|---|
committer | parsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2010-05-21 23:06:20 +0000 |
commit | 96db2bd339ca52d7af93621407c1607085a77fb0 (patch) | |
tree | 5610f80c6323be750ce05b6a9a0931efbb0905f7 /TAO/TAO_IDL | |
parent | ffed642fe355fe95f7f93ef6e1b33ff011eb75ce (diff) | |
download | ATCD-96db2bd339ca52d7af93621407c1607085a77fb0.tar.gz |
ChangeLogTag: Fri May 21 23:04:30 UTC 2010 Jeff Parsons <j.parsons@vanderbilt.edu>ChangeLog
Diffstat (limited to 'TAO/TAO_IDL')
26 files changed, 551 insertions, 420 deletions
diff --git a/TAO/TAO_IDL/ast/ast_component.cpp b/TAO/TAO_IDL/ast/ast_component.cpp index 17c205c4b9e..fd68d16fc5e 100644 --- a/TAO/TAO_IDL/ast/ast_component.cpp +++ b/TAO/TAO_IDL/ast/ast_component.cpp @@ -69,13 +69,16 @@ AST_Component::redefine (AST_Interface *from) AST_Decl * AST_Component::look_in_inherited (UTL_ScopedName *e, - bool treat_as_ref) + bool full_def_only) { AST_Decl *d = 0; - + if (this->pd_base_component != 0) { - d = this->pd_base_component->lookup_by_name (e, treat_as_ref); + d = + this->pd_base_component->lookup_by_name_r ( + e, + full_def_only); } return d; @@ -84,7 +87,7 @@ AST_Component::look_in_inherited (UTL_ScopedName *e, // Look through supported interface list. AST_Decl * AST_Component::look_in_supported (UTL_ScopedName *e, - bool) + bool full_def_only) { AST_Decl *d = 0; AST_Type **is = 0; @@ -93,16 +96,12 @@ AST_Component::look_in_supported (UTL_ScopedName *e, // Can't look in an interface which was not yet defined. if (!this->is_defined ()) { - idl_global->err ()->fwd_decl_lookup (this, - e); + idl_global->err ()->fwd_decl_lookup (this, e); return 0; } // OK, loop through supported interfaces. - // (Don't leave the inheritance hierarchy, no module or global ...) - // Find all and report ambiguous results as error. - for (nis = this->n_supports (), is = this->supports (); nis > 0; nis--, is++) @@ -115,7 +114,7 @@ AST_Component::look_in_supported (UTL_ScopedName *e, AST_Interface *i = AST_Interface::narrow_from_decl (*is); - d = (i)->lookup_by_name (e); + d = (i)->lookup_by_name_r (e, full_def_only); if (d != 0) { @@ -144,6 +143,20 @@ AST_Component::n_supports (void) const return this->n_inherits (); } +AST_Decl * +AST_Component::special_lookup (UTL_ScopedName *e, + bool full_def_only) +{ + AST_Decl *d = this->look_in_inherited (e, full_def_only); + + if (d == 0) + { + d = this->look_in_supported (e, full_def_only); + } + + return d; +} + void AST_Component::destroy (void) { diff --git a/TAO/TAO_IDL/ast/ast_decl.cpp b/TAO/TAO_IDL/ast/ast_decl.cpp index 043b69e96d8..8d9588d811f 100644 --- a/TAO/TAO_IDL/ast/ast_decl.cpp +++ b/TAO/TAO_IDL/ast/ast_decl.cpp @@ -805,10 +805,10 @@ AST_Decl::has_ancestor (AST_Decl *s) !i.done (); i.advance ()) { - AST_Module **m = 0; - i.next (m); + AST_Module **mm = 0; + i.next (mm); - for (UTL_ScopeActiveIterator si (*m, UTL_Scope::IK_decls); + for (UTL_ScopeActiveIterator si (*mm, UTL_Scope::IK_decls); !si.is_done (); si.next ()) { @@ -1218,7 +1218,7 @@ AST_Decl::set_line (long l) this->pd_line = l; } -ACE_CString +ACE_CString & AST_Decl::file_name (void) { return this->pd_file_name; @@ -1540,6 +1540,37 @@ AST_Decl::contains_wstring (int val) this->contains_wstring_ = val; } +bool +AST_Decl::masking_checks (AST_Decl *mod) +{ + if (!this->pd_local_name->case_compare (mod->local_name ())) + { + return true; + } + + AST_Module *me_mod = AST_Module::narrow_from_decl (this); + AST_Module *of_mod = AST_Module::narrow_from_decl (mod); + + if (me_mod != 0 && of_mod != 0) + { + for (ACE_Unbounded_Set<AST_Module *>::CONST_ITERATOR i ( + of_mod->prev_mods ()); + !i.done (); + i.advance ()) + { + AST_Module **m = 0; + i.next (m); + + if (*m == me_mod) + { + return true; + } + } + } + + return false; +} + //Narrowing methods for AST_Decl. IMPL_NARROW_FROM_DECL(AST_Decl) diff --git a/TAO/TAO_IDL/ast/ast_generator.cpp b/TAO/TAO_IDL/ast/ast_generator.cpp index 225bc3b1748..fbc8b0d0e7d 100644 --- a/TAO/TAO_IDL/ast/ast_generator.cpp +++ b/TAO/TAO_IDL/ast/ast_generator.cpp @@ -166,30 +166,32 @@ AST_Generator::create_module (UTL_Scope *s, // 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. - AST_Decl *d = ScopeAsDecl (s); - AST_Decl::NodeType nt = d->node_type (); + m = AST_Module::narrow_from_scope (s); - if (nt == AST_Decl::NT_module || nt == AST_Decl::NT_root) + if (m != 0) { - // Also check this to week out a template module or its - // instantiation. - m = AST_Module::narrow_from_decl (d); - - if (m != 0) + for (ACE_Unbounded_Set<AST_Module *>::CONST_ITERATOR i ( + m->prev_mods ()); + !i.done (); + i.advance ()) { - // 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_prev_mods (n->last_component ()); - - if (d != 0) + AST_Module **mm = 0; + i.next (mm); + + for (UTL_ScopeActiveIterator si (*mm, UTL_Scope::IK_decls); + !si.is_done (); + si.next ()) { - if (d->node_type () == AST_Decl::NT_module) + AST_Decl *d = si.item (); + + if (retval->local_name ()->case_compare (d->local_name ())) { m = AST_Module::narrow_from_decl (d); - - retval->add_to_previous (m); + + if (m != 0) + { + retval->add_to_previous (m); + } } } } diff --git a/TAO/TAO_IDL/ast/ast_home.cpp b/TAO/TAO_IDL/ast/ast_home.cpp index 665d79aad24..986bef94d3a 100644 --- a/TAO/TAO_IDL/ast/ast_home.cpp +++ b/TAO/TAO_IDL/ast/ast_home.cpp @@ -63,13 +63,14 @@ AST_Home::~AST_Home (void) AST_Decl * AST_Home::look_in_inherited (UTL_ScopedName *e, - bool treat_as_ref) + bool full_def_only) { AST_Decl *d = 0; if (this->pd_base_home != 0) { - d = this->pd_base_home->lookup_by_name (e, treat_as_ref); + d = + this->pd_base_home->lookup_by_name (e, full_def_only); } return d; @@ -78,7 +79,7 @@ AST_Home::look_in_inherited (UTL_ScopedName *e, // Look through supported interface list. AST_Decl * AST_Home::look_in_supported (UTL_ScopedName *e, - bool /* treat_as_ref */) + bool full_def_only) { AST_Decl *d = 0; AST_Type **is = 0; @@ -109,7 +110,7 @@ AST_Home::look_in_supported (UTL_ScopedName *e, AST_Interface *i = AST_Interface::narrow_from_decl (*is); - d = (i)->lookup_by_name (e); + d = (i)->lookup_by_name_r (e, full_def_only); if (d != 0) { @@ -120,6 +121,20 @@ AST_Home::look_in_supported (UTL_ScopedName *e, return d; } +AST_Decl * +AST_Home::special_lookup (UTL_ScopedName *e, + bool full_def_only) +{ + AST_Decl *d = this->look_in_inherited (e, full_def_only); + + if (d == 0) + { + d = this->look_in_supported (e, full_def_only); + } + + return d; +} + AST_Home * AST_Home::base_home (void) const { diff --git a/TAO/TAO_IDL/ast/ast_interface.cpp b/TAO/TAO_IDL/ast/ast_interface.cpp index 553c40db036..8db48b96ec9 100644 --- a/TAO/TAO_IDL/ast/ast_interface.cpp +++ b/TAO/TAO_IDL/ast/ast_interface.cpp @@ -809,7 +809,7 @@ AST_Interface::redef_clash (void) // Look through inherited interfaces. AST_Decl * AST_Interface::look_in_inherited (UTL_ScopedName *e, - bool /* treat_as_ref */) + bool full_def_only) { AST_Decl *d = 0; AST_Decl *d_before = 0; @@ -839,7 +839,7 @@ AST_Interface::look_in_inherited (UTL_ScopedName *e, continue; } - d = (i)->lookup_by_name (e); + d = (i)->lookup_by_name_r (e, full_def_only); if (d != 0) { if (d_before == 0) @@ -881,7 +881,8 @@ AST_Interface::look_in_inherited (UTL_ScopedName *e, } AST_Decl * -AST_Interface::look_in_inherited_local (Identifier *e) +AST_Interface::look_in_inherited_local (Identifier *e, + bool full_def_only) { // Can't look in an interface which was not yet defined. if (!this->is_defined ()) @@ -906,7 +907,7 @@ AST_Interface::look_in_inherited_local (Identifier *e) continue; } - d = i->lookup_by_name_local (e, false); + d = i->lookup_by_name_local (e, full_def_only); if (d != 0) { @@ -974,6 +975,27 @@ AST_Interface::legal_for_primary_key (void) const return false; } +AST_Decl * +AST_Interface::special_lookup (UTL_ScopedName *e, + bool full_def_only) +{ + AST_Decl *d = this->look_in_inherited_local (e->head (), + full_def_only); + + if (d != 0) + { + UTL_Scope *s = DeclAsScope (d); + UTL_ScopedName *sn = + static_cast<UTL_ScopedName *> (e->tail ()); + + return (s != 0 && sn != 0 + ? s->lookup_by_name_r (sn, full_def_only) + : d); + } + + return 0; +} + void AST_Interface::destroy (void) { diff --git a/TAO/TAO_IDL/ast/ast_interface_fwd.cpp b/TAO/TAO_IDL/ast/ast_interface_fwd.cpp index ad19dbcb19c..0a5412dd4c6 100644 --- a/TAO/TAO_IDL/ast/ast_interface_fwd.cpp +++ b/TAO/TAO_IDL/ast/ast_interface_fwd.cpp @@ -134,8 +134,8 @@ AST_InterfaceFwd::full_def_seen (void) { AST_Module *m = AST_Module::narrow_from_scope (s); AST_Decl *d = - m->look_in_prev_mods (this->local_name (), - false); + m->look_in_prev_mods_local (this->local_name (), + false); if (0 != d) { @@ -219,7 +219,8 @@ AST_InterfaceFwd::is_defined (void) if (0 != m) { - AST_Decl *d = m->look_in_prev_mods (this->local_name ()); + AST_Decl *d = + m->look_in_prev_mods_local (this->local_name ()); if (0 != d) { diff --git a/TAO/TAO_IDL/ast/ast_module.cpp b/TAO/TAO_IDL/ast/ast_module.cpp index 7d95b729334..c3b569bf709 100644 --- a/TAO/TAO_IDL/ast/ast_module.cpp +++ b/TAO/TAO_IDL/ast/ast_module.cpp @@ -199,7 +199,7 @@ AST_Module::referenced (AST_Decl *e, } AST_Decl *d = - this->look_in_prev_mods (e->local_name (), true); + this->look_in_prev_mods_local (e->local_name (), true); if (0 == d) { @@ -213,29 +213,63 @@ AST_Module::referenced (AST_Decl *e, void AST_Module::add_to_previous (AST_Module *m) { - // This will eventually replace the individual declarations - // list below. this->prev_mods_.insert (m); - - for (ACE_Unbounded_Set<AST_Module *>::CONST_ITERATOR i ( - m->prev_mods ()); - !i.done (); - i.advance ()) +} + +AST_Decl * +AST_Module::look_in_prev_mods_local (Identifier *e, + bool ignore_fwd) +{ + AST_Module **m = 0; + AST_Decl *d = 0; + + // If there are more than two openings of this module, we want + // to get the last one - the one that will have the decls from + // all the previous openings added to previous_. + for (ACE_Unbounded_Set<AST_Module *>::CONST_ITERATOR iter ( + this->prev_mods_); + !iter.done (); + iter.advance ()) { - AST_Module **mm = 0; - i.next (mm); + iter.next (m); - this->prev_mods_.insert (*mm); + for (UTL_ScopeActiveIterator i (*m, UTL_Scope::IK_decls); + !i.is_done (); + i.next ()) + { + d = i.item (); + + if (ignore_fwd) + { + AST_Decl::NodeType nt = d->node_type (); + + if (nt == AST_Decl::NT_interface_fwd + || nt == AST_Decl::NT_eventtype_fwd + || nt == AST_Decl::NT_component_fwd + || nt == AST_Decl::NT_struct_fwd + || nt == AST_Decl::NT_union_fwd + || nt == AST_Decl::NT_valuetype_fwd) + { + continue; + } + } + + if (e->case_compare (d->local_name ())) + { + return d; + } + } } + + return 0; } AST_Decl * -AST_Module::look_in_prev_mods (Identifier *e, - bool ignore_fwd) +AST_Module::look_in_prev_mods (UTL_ScopedName *e, + bool full_def_only) { AST_Module **m = 0; AST_Decl *d = 0; - AST_Decl *retval = 0; // If there are more than two openings of this module, we want // to get the last one - the one that will have the decls from @@ -253,7 +287,7 @@ AST_Module::look_in_prev_mods (Identifier *e, { d = i.item (); - if (ignore_fwd) + if (full_def_only) { AST_Decl::NodeType nt = d->node_type (); @@ -268,14 +302,30 @@ AST_Module::look_in_prev_mods (Identifier *e, } } - if (e->case_compare (d->local_name ())) + if (e->head ()->case_compare (d->local_name ())) { - retval = d; + UTL_Scope *s = DeclAsScope (d); + UTL_ScopedName *sn = + static_cast<UTL_ScopedName *> (e->tail ()); + + if (sn == 0) + { + return d; + } + else if (s != 0) + { + d = s->lookup_by_name_r (sn, full_def_only); + + if (d != 0) + { + return d; + } + } } } } - return retval; + return 0; } ACE_Unbounded_Set<AST_Module *> & @@ -309,6 +359,13 @@ AST_Module::from_inst (AST_Template_Module_Inst *node) this->from_inst_ = node; } +AST_Decl * +AST_Module::special_lookup (UTL_ScopedName *e, + bool full_def_only) +{ + return this->look_in_prev_mods (e, full_def_only); +} + //================================================ AST_PredefinedType * diff --git a/TAO/TAO_IDL/ast/ast_valuetype.cpp b/TAO/TAO_IDL/ast/ast_valuetype.cpp index e98a3f22c54..b61076f528e 100644 --- a/TAO/TAO_IDL/ast/ast_valuetype.cpp +++ b/TAO/TAO_IDL/ast/ast_valuetype.cpp @@ -229,7 +229,7 @@ AST_ValueType::will_have_factory (void) // Look through supported interface list. AST_Decl * AST_ValueType::look_in_supported (UTL_ScopedName *e, - bool) + bool full_def_only) { AST_Decl *d = 0; AST_Decl *d_before = 0; @@ -259,7 +259,7 @@ AST_ValueType::look_in_supported (UTL_ScopedName *e, AST_Interface *i = AST_Interface::narrow_from_decl (*is); - d = (i)->lookup_by_name (e); + d = (i)->lookup_by_name_r (e, full_def_only); if (d != 0) { @@ -301,6 +301,20 @@ AST_ValueType::look_in_supported (UTL_ScopedName *e, return d_before; } +AST_Decl * +AST_ValueType::special_lookup (UTL_ScopedName *e, + bool full_def_only) +{ + AST_Decl *d = this->look_in_inherited (e, full_def_only); + + if (d == 0) + { + d = this->look_in_supported (e, full_def_only); + } + + return d; +} + bool AST_ValueType::legal_for_primary_key (void) const { diff --git a/TAO/TAO_IDL/be/be_generator.cpp b/TAO/TAO_IDL/be/be_generator.cpp index 2989f0a498c..a305a7e7ac3 100644 --- a/TAO/TAO_IDL/be/be_generator.cpp +++ b/TAO/TAO_IDL/be/be_generator.cpp @@ -183,30 +183,32 @@ be_generator::create_module (UTL_Scope *s, // 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. - AST_Decl *d = ScopeAsDecl (s); - AST_Decl::NodeType nt = d->node_type (); + m = AST_Module::narrow_from_scope (s); - if (nt == AST_Decl::NT_module || nt == AST_Decl::NT_root) + if (m != 0) { - // Also check this to week out a template module or its - // instantiation. - m = AST_Module::narrow_from_decl (d); - - if (m != 0) + for (ACE_Unbounded_Set<AST_Module *>::CONST_ITERATOR i ( + m->prev_mods ()); + !i.done (); + i.advance ()) { - // 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_prev_mods (n->last_component ()); - - if (d != 0) + AST_Module **mm = 0; + i.next (mm); + + for (UTL_ScopeActiveIterator si (*mm, UTL_Scope::IK_decls); + !si.is_done (); + si.next ()) { - if (d->node_type () == AST_Decl::NT_module) + AST_Decl *d = si.item (); + + if (retval->local_name ()->case_compare (d->local_name ())) { m = AST_Module::narrow_from_decl (d); - - retval->add_to_previous (m); + + if (m != 0) + { + retval->add_to_previous (m); + } } } } diff --git a/TAO/TAO_IDL/fe/fe_component_header.cpp b/TAO/TAO_IDL/fe/fe_component_header.cpp index bec9533d533..438dc06a6c9 100644 --- a/TAO/TAO_IDL/fe/fe_component_header.cpp +++ b/TAO/TAO_IDL/fe/fe_component_header.cpp @@ -152,7 +152,7 @@ FE_ComponentHeader::compile_supports (UTL_NameList *supports) { AST_Module *m = AST_Module::narrow_from_decl (sad); - d = m->look_in_prev_mods (item->last_component ()); + d = m->look_in_prev_mods_local (item->last_component ()); } } diff --git a/TAO/TAO_IDL/fe/fe_interface_header.cpp b/TAO/TAO_IDL/fe/fe_interface_header.cpp index 72c3f414e81..a89b3277c7f 100644 --- a/TAO/TAO_IDL/fe/fe_interface_header.cpp +++ b/TAO/TAO_IDL/fe/fe_interface_header.cpp @@ -322,7 +322,7 @@ FE_InterfaceHeader::compile_inheritance (UTL_NameList *ifaces, { AST_Module *m = AST_Module::narrow_from_decl (sad); - d = m->look_in_prev_mods (item->last_component ()); + d = m->look_in_prev_mods_local (item->last_component ()); } } diff --git a/TAO/TAO_IDL/fe/fe_obv_header.cpp b/TAO/TAO_IDL/fe/fe_obv_header.cpp index fdf88741fdd..5c90e313661 100644 --- a/TAO/TAO_IDL/fe/fe_obv_header.cpp +++ b/TAO/TAO_IDL/fe/fe_obv_header.cpp @@ -214,7 +214,7 @@ FE_OBVHeader::compile_supports (UTL_NameList *supports) { AST_Module *m = AST_Module::narrow_from_decl (sad); - d = m->look_in_prev_mods (item->last_component ()); + d = m->look_in_prev_mods_local (item->last_component ()); } } diff --git a/TAO/TAO_IDL/fe/idl.ll b/TAO/TAO_IDL/fe/idl.ll index e43b13a2dd2..40b16b774d5 100644 --- a/TAO/TAO_IDL/fe/idl.ll +++ b/TAO/TAO_IDL/fe/idl.ll @@ -1230,8 +1230,7 @@ idl_find_node (char *s) if (node != 0) { - d = idl_global->scopes ().top_non_null ()->lookup_by_name (node, - true); + d = idl_global->scopes ().top_non_null ()->lookup_by_name (node); if (d == 0) { diff --git a/TAO/TAO_IDL/fe/lex.yy.cpp b/TAO/TAO_IDL/fe/lex.yy.cpp index 84a9dc1f0e0..7b5e96aeae0 100644 --- a/TAO/TAO_IDL/fe/lex.yy.cpp +++ b/TAO/TAO_IDL/fe/lex.yy.cpp @@ -3716,8 +3716,7 @@ idl_find_node (char *s) if (node != 0) { - d = idl_global->scopes ().top_non_null ()->lookup_by_name (node, - true); + d = idl_global->scopes ().top_non_null ()->lookup_by_name (node); if (d == 0) { diff --git a/TAO/TAO_IDL/include/ast_component.h b/TAO/TAO_IDL/include/ast_component.h index 820be69593f..d40746b9b62 100644 --- a/TAO/TAO_IDL/include/ast_component.h +++ b/TAO/TAO_IDL/include/ast_component.h @@ -33,11 +33,11 @@ public: // Extend lookup to the base component. virtual AST_Decl *look_in_inherited (UTL_ScopedName *e, - bool treat_as_ref); + bool full_def_only); // Extend lookup to the supported interfaces. virtual AST_Decl *look_in_supported (UTL_ScopedName *e, - bool treat_as_ref); + bool full_def_only); // Accessors. @@ -46,6 +46,10 @@ public: AST_Type **supports (void) const; long n_supports (void) const; + + // Override for component of UTL_Scope method. + virtual AST_Decl *special_lookup (UTL_ScopedName *e, + bool full_def_only); // Cleanup function. virtual void destroy (void); diff --git a/TAO/TAO_IDL/include/ast_decl.h b/TAO/TAO_IDL/include/ast_decl.h index f750c65d906..b8434de1ea7 100644 --- a/TAO/TAO_IDL/include/ast_decl.h +++ b/TAO/TAO_IDL/include/ast_decl.h @@ -192,7 +192,7 @@ public: long line (void); void set_line (long l); - ACE_CString file_name (void); + ACE_CString & file_name (void); void set_file_name (ACE_CString s); UTL_ScopedName *name (void); @@ -289,7 +289,12 @@ public: // Useful for GIOP to know if a wstring is being marshaled. virtual int contains_wstring (void); void contains_wstring (int val); - + + // Additional checks when we think we have caught an IDL + // masking scope error in a lookup, which starts simply with + // a comparison of names in a scope masking queue. + bool masking_checks (AST_Decl *mod); + protected: // These are not private because they're used by // be_predefined_type' constructor and can be called diff --git a/TAO/TAO_IDL/include/ast_home.h b/TAO/TAO_IDL/include/ast_home.h index 4d7f38ae283..df69e21c001 100644 --- a/TAO/TAO_IDL/include/ast_home.h +++ b/TAO/TAO_IDL/include/ast_home.h @@ -26,11 +26,15 @@ public: // Extend lookup to the base home. virtual AST_Decl *look_in_inherited (UTL_ScopedName *e, - bool treat_as_ref); + bool full_def_only); // Extend lookup to the supported interfaces. virtual AST_Decl *look_in_supported (UTL_ScopedName *e, - bool treat_as_ref); + bool full_def_only); + + // Overridden for homes from the UTL_Scope method. + virtual AST_Decl *special_lookup (UTL_ScopedName *, + bool full_def_only); // Accessors. diff --git a/TAO/TAO_IDL/include/ast_interface.h b/TAO/TAO_IDL/include/ast_interface.h index 9f348a4d44c..54e014d0848 100644 --- a/TAO/TAO_IDL/include/ast_interface.h +++ b/TAO/TAO_IDL/include/ast_interface.h @@ -130,14 +130,18 @@ public: // Look through inherited interfaces. virtual AST_Decl *look_in_inherited (UTL_ScopedName *e, - bool treat_as_ref); + bool full_def_only); - AST_Decl *look_in_inherited_local (Identifier *e); + AST_Decl *look_in_inherited_local (Identifier *e, + bool full_def_only = false); // Recursively called on valuetype to check for legal use as // a primary key. Overridden for valuetype, struct, sequence, // union, array, typedef, and interface. virtual bool legal_for_primary_key (void) const; + + virtual AST_Decl *special_lookup (UTL_ScopedName *e, + bool full_def_only); // Cleanup function. virtual void destroy (void); diff --git a/TAO/TAO_IDL/include/ast_module.h b/TAO/TAO_IDL/include/ast_module.h index 94cfe541447..e7a7e504890 100644 --- a/TAO/TAO_IDL/include/ast_module.h +++ b/TAO/TAO_IDL/include/ast_module.h @@ -115,10 +115,14 @@ public: // own 'previous' set. void add_to_previous (AST_Module *m); - // Called to check for some declaration + // Called to look up some declaration // in a previous opening of this module. - AST_Decl *look_in_prev_mods (Identifier *e, - bool ignore_fwd = false); + AST_Decl *look_in_prev_mods_local (Identifier *e, + bool ignore_fwd = false); + // Called to look up some declaration + // in a previous opening of this module. + AST_Decl *look_in_prev_mods (UTL_ScopedName *e, + bool full_def_only = false); // Accessor to the member. ACE_Unbounded_Set<AST_Module *> &prev_mods (void); @@ -132,6 +136,10 @@ public: // Accessors for the member. AST_Template_Module_Inst *from_inst (void) const; void from_inst (AST_Template_Module_Inst *node); + + // Override that looks in previous openings. + virtual AST_Decl *special_lookup (UTL_ScopedName *e, + bool full_def_only); public: static AST_Decl::NodeType const NT; diff --git a/TAO/TAO_IDL/include/ast_valuetype.h b/TAO/TAO_IDL/include/ast_valuetype.h index d9400bfb8bd..35ea20f10ae 100644 --- a/TAO/TAO_IDL/include/ast_valuetype.h +++ b/TAO/TAO_IDL/include/ast_valuetype.h @@ -47,7 +47,11 @@ public: // Look up a scoped name in the supported interface list. virtual AST_Decl *look_in_supported (UTL_ScopedName *, - bool treat_as_ref); + bool full_def_only); + + // Overridden for valuetype from UTL_Scope method. + virtual AST_Decl *special_lookup (UTL_ScopedName *, + bool full_def_only); // Recursively called on valuetype to check for legal use as // a primary key. Overridden for valuetype, struct, sequence, diff --git a/TAO/TAO_IDL/include/idl_global.h b/TAO/TAO_IDL/include/idl_global.h index 92364519f64..1d517d4c896 100644 --- a/TAO/TAO_IDL/include/idl_global.h +++ b/TAO/TAO_IDL/include/idl_global.h @@ -622,6 +622,9 @@ public: void add_ciao_ami_recep_names (const char *s); ACE_Unbounded_Queue<char *> & ciao_ami_recep_names (void); // Accessor/mutator for the ciao_ami_recep_names_ member. + + ACE_Unbounded_Queue<AST_Decl *> & masking_scopes (void); + // Accessor for the member FILE * open_included_file (char const * filename, char const *& directory); @@ -708,7 +711,7 @@ public: void original_local_name (Identifier *local_name); // Strips _cxx_ prefix for use in port names. - + private: bool check_one_seq_of_param (FE_Utils::T_PARAMLIST_INFO *list, ACE_CString ¶m_id, @@ -859,6 +862,10 @@ private: ACE_Unbounded_Queue<char *> ciao_ami_recep_names_; // Receptacles that get a sendc_ version added for AMI4CCM. + + ACE_Unbounded_Queue<AST_Decl *> masking_scopes_; + // Used to check for an incorrect lookup success that should + // have been masked by an inner scope of the same name. }; #endif //_IDL_IDL_GLOBAL_HH diff --git a/TAO/TAO_IDL/include/utl_err.h b/TAO/TAO_IDL/include/utl_err.h index 8378849cc88..6272fddd83a 100644 --- a/TAO/TAO_IDL/include/utl_err.h +++ b/TAO/TAO_IDL/include/utl_err.h @@ -362,6 +362,12 @@ public: // Given a template param of the form 'sequence<T>', the // 'T' must match a previous param in the list. void mismatch_seq_of_param (const char *param_id); + + // Informative message when a lookup fails because a + // masking scope has not been correctly differentiated + // in the scoped name from the scope it masks. + void scope_masking_error (AST_Decl *masked, + AST_Decl *loc); }; #endif // _UTL_ERR_UTL_ERR_HH diff --git a/TAO/TAO_IDL/include/utl_scope.h b/TAO/TAO_IDL/include/utl_scope.h index ae9f28aab49..9dfff99a47d 100644 --- a/TAO/TAO_IDL/include/utl_scope.h +++ b/TAO/TAO_IDL/include/utl_scope.h @@ -173,6 +173,9 @@ public: // Name Lookup Mechanism AST_Decl *lookup_by_name (UTL_ScopedName *, bool full_def_only = false); + + AST_Decl *lookup_by_name_r (UTL_ScopedName *, + bool full_def_only); // Look up the Identifier * specified only in the local scope. AST_Decl *lookup_by_name_local (Identifier *, @@ -184,8 +187,13 @@ public: // Look up one of the pseudo-object types. AST_Decl *lookup_pseudo (Identifier *); - virtual AST_Decl *look_in_prev_mods (Identifier *e, - bool ignore_fwd = false); + virtual AST_Decl *look_in_prev_mods_local (Identifier *e, + bool ignore_fwd = false); + + // A no-op here, overridden for types like interface + // (look_in_inherited), modules (look_in_prev_mods) etc. + virtual AST_Decl *special_lookup (UTL_ScopedName *e, + bool ful_def_only); // How many entries are used? virtual unsigned long nmembers (void); @@ -314,7 +322,7 @@ protected: }; WHICH_PSEUDO which_pseudo_; - + // Friend class UTL_ScopeActiveIterator defines active iterator for // UTL_Scope. Definition follows below. friend class UTL_ScopeActiveIterator; @@ -501,6 +509,8 @@ private: iter_lookup_by_name_local (AST_Decl *d, UTL_ScopedName *e, bool full_def_only = false); + + AST_Decl *local_checks (AST_Decl *d, bool full_def_only); }; // Active iterator for a UTL_Scope node diff --git a/TAO/TAO_IDL/util/utl_err.cpp b/TAO/TAO_IDL/util/utl_err.cpp index 74adf33c822..556e1f49260 100644 --- a/TAO/TAO_IDL/util/utl_err.cpp +++ b/TAO/TAO_IDL/util/utl_err.cpp @@ -1521,3 +1521,58 @@ UTL_Error::mismatch_seq_of_param (const char *param_id) idl_global->set_err_count (idl_global->err_count () + 1); } +void +UTL_Error::scope_masking_error (AST_Decl *masked, + AST_Decl *masking) +{ + const char *this_file = idl_global->filename ()->get_string (); + const char *masked_file = masked->file_name ().c_str (); + const char *masking_file = masking->file_name ().c_str (); + + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("%C: \"%C\", line %d: Did you mean \"::%C\"\n") + ACE_TEXT (" declared at "), + idl_global->prog_name (), + this_file, + idl_global->lineno (), + masked->full_name () )); + + const bool same_file = + (0 == ACE_OS::strcmp (this_file, masked_file)); + + if (!same_file) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("%C "), + masked_file)); + } + + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("line %d but hidden by local \""), + masked->line ())); + + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("::%C\""), + masking->full_name ())); + + const bool same_file_again = + (same_file + && 0 == ACE_OS::strcmp (this_file, masking_file)); + + if (!same_file_again) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("\n") + ACE_TEXT (" declared at %C "), + masking_file)); + } + else + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT (" at "))); + } + + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("line %d ?\n"), + masking->line () )); +} diff --git a/TAO/TAO_IDL/util/utl_global.cpp b/TAO/TAO_IDL/util/utl_global.cpp index 6d403019734..fa29ecbb700 100644 --- a/TAO/TAO_IDL/util/utl_global.cpp +++ b/TAO/TAO_IDL/util/utl_global.cpp @@ -1373,6 +1373,12 @@ IDL_GlobalData::ciao_ami_recep_names (void) return this->ciao_ami_recep_names_; } +ACE_Unbounded_Queue<AST_Decl *> & +IDL_GlobalData::masking_scopes (void) +{ + return this->masking_scopes_; +} + ACE_Hash_Map_Manager<char *, char *, ACE_Null_Mutex> & IDL_GlobalData::file_prefixes (void) { diff --git a/TAO/TAO_IDL/util/utl_scope.cpp b/TAO/TAO_IDL/util/utl_scope.cpp index 807023f4db3..288cb29ef0f 100644 --- a/TAO/TAO_IDL/util/utl_scope.cpp +++ b/TAO/TAO_IDL/util/utl_scope.cpp @@ -982,7 +982,7 @@ UTL_Scope::lookup_pseudo (Identifier *e) if (this->which_pseudo_ == PSEUDO_TYPECODE) { - d = this->look_in_prev_mods (e); + d = this->look_in_prev_mods_local (e); if (d != 0) { @@ -997,7 +997,15 @@ UTL_Scope::lookup_pseudo (Identifier *e) } AST_Decl * -UTL_Scope::look_in_prev_mods (Identifier *, bool /* ignore_fwd */) +UTL_Scope::look_in_prev_mods_local (Identifier *, + bool /* ignore_fwd */) +{ + return 0; +} + +AST_Decl * +UTL_Scope::special_lookup (UTL_ScopedName *, + bool /* full_def_only */) { return 0; } @@ -1138,8 +1146,6 @@ UTL_Scope::look_in_supported (UTL_ScopedName *, return 0; } -#define OVERHAUL - AST_Decl * UTL_Scope::lookup_by_name_local (Identifier *e, bool full_def_only) @@ -1231,7 +1237,7 @@ UTL_Scope::lookup_by_name_local (Identifier *e, if (m != 0) { - d = m->look_in_prev_mods (e); + d = m->look_in_prev_mods_local (e); if (0 != d && full_def_only && !d->is_defined ()) { @@ -1274,7 +1280,6 @@ UTL_Scope::lookup_by_name_local (Identifier *e, return d; } -#if defined (OVERHAUL) AST_Decl * UTL_Scope::lookup_by_name (UTL_ScopedName *e, bool full_def_only) @@ -1285,101 +1290,109 @@ UTL_Scope::lookup_by_name (UTL_ScopedName *e, return 0; } - UTL_ScopedName *work = e; + UTL_ScopedName *work_name = e; + UTL_Scope *work_scope = this; /// If name starts with "::" or "" start lookup in global scope, /// if we're not there already, short_circuiting the /// scope-expanding iteration below. - if (this->is_global_name (e->head ())) + bool global_scope_name = + this->is_global_name (e->head ()); + + if (global_scope_name) { - work = static_cast<UTL_ScopedName *> (e->tail ()); - - if (this != idl_global->root ()) - { - return - idl_global->root ()->lookup_by_name (work, - full_def_only); - } + work_name = static_cast<UTL_ScopedName *> (e->tail ()); + work_scope = idl_global->root (); } - /// Before proceeding to normal lookup, check if the name - /// matches a template module parameter. If so, the return - /// value is created on the heap and is owned by the caller - /// of this lookup. - if (work->length () == 1) - { - AST_Param_Holder *param_holder = - UTL_Scope::match_param (e); - - // Since we are inside the scope of a template module, any - // single-segment scoped name that matches a template - // parameter name has to be a reference to that parameter, - // so we return the created placeholder. If there's no - // match, 0 is returned, and we proceed with the regular - // lookup. - if (param_holder != 0) - { - return param_holder; - } - } - - AST_Decl *d = 0; - UTL_Scope *s = this; + AST_Decl *d = + work_scope->lookup_by_name_r (work_name, full_def_only); + + UTL_Scope *outer = ScopeAsDecl (work_scope)->defined_in (); - d = s->lookup_by_name_local (work->head (), - full_def_only); - - UTL_Scope *outer = ScopeAsDecl (s)->defined_in (); + ACE_Unbounded_Queue<AST_Decl *> & masks = + idl_global->masking_scopes (); /// If all else fails, expand the scope, otherwise /// try to match the rest of the scoped name. - if (d == 0) + while (d == 0 && outer != 0) { - return (outer == 0 - ? 0 - : outer->lookup_by_name (work, full_def_only)); + d = outer->lookup_by_name_r (work_name, full_def_only); + + AST_Decl *s = ScopeAsDecl (outer); + outer = s->defined_in (); } - else + + if (!global_scope_name && d != 0) { - UTL_ScopedName *sn = - static_cast<UTL_ScopedName *> (work->tail ()); + ACE_CDR::ULong slot = 0UL; + const char *head = e->head ()->get_string (); + AST_Decl *outer_scope = 0; - if (sn != 0) + for (ACE_Unbounded_Queue<AST_Decl *>::CONST_ITERATOR i (masks); + !i.done (); + i.advance (), ++slot) { - d = this->iter_lookup_by_name_local (d, - sn, - full_def_only); + AST_Decl **item = 0; + i.next (item); + + /// The first queue item (last enqueued) will always + /// match e->head(), but does not indicate an error. + if (slot == 0UL) + { + outer_scope = *item; + continue; + } - if (d == 0) + const char *lname = + (*item)->local_name ()->get_string (); + + if (ACE_OS::strcmp (lname, head) == 0) { - return (outer == 0 - ? 0 - : outer->lookup_by_name (work, - full_def_only)); + if (!(*item)->masking_checks (outer_scope)) + { + idl_global->err ()->scope_masking_error ( + d, + (*item)); + + d = 0; + break; + } } } } + masks.reset (); return d; } -#else -// Implements lookup by name for scoped names. + AST_Decl * -UTL_Scope::lookup_by_name (UTL_ScopedName *e, - bool treat_as_ref, - bool in_parent, - bool full_def_only) +UTL_Scope::lookup_by_name_r (UTL_ScopedName *e, + bool full_def_only) { AST_Decl *d = 0; - UTL_Scope *s = 0; - AST_Type *t = 0; + AST_Decl *tmp = 0; - // Empty name? Error. - if (e == 0) + // Will catch Object, TypeCode, TCKind, ValueBase and + // AbstractBase. A non-zero result of this lookup determines the + // generation of some #includes and, whether successful or not, + // incurs no extra overhead. + d = this->lookup_pseudo (e->head ()); + + if (d != 0) + { + return d; + } + + if (this->idl_keyword_clash (e->head ()) != 0) { return 0; } - + + /// Before proceeding to normal lookup, check if the name + /// matches a template module parameter. If so, the return + /// value is created on the heap and is owned by the caller + /// of this lookup. if (e->length () == 1) { AST_Param_Holder *param_holder = @@ -1397,266 +1410,74 @@ UTL_Scope::lookup_by_name (UTL_ScopedName *e, } } - // If name starts with "::" or "" start lookup in global scope. - if (this->is_global_name (e->head ())) - { - // Get parent scope. - d = ScopeAsDecl (this); - - if (0 == d) - { - return 0; - } - - s = d->defined_in (); - - // If this is the global scope.. - if (0 == s) - { - // Look up tail of name starting here. - d = lookup_by_name ((UTL_ScopedName *) e->tail (), - treat_as_ref, - in_parent, - full_def_only); - - // Now return whatever we have. - return d; - } - - // OK, not global scope yet, so simply iterate with parent scope. - d = s->lookup_by_name (e, - treat_as_ref, - in_parent, - full_def_only); + bool in_corba = + ACE_OS::strcmp (e->head ()->get_string (), "CORBA") == 0; - // If treat_as_ref is true and d is not NULL, add d to - // set of nodes referenced here. - if (treat_as_ref && d != 0) + for (UTL_ScopeActiveIterator i (this, UTL_Scope::IK_decls); + !i.is_done (); + i.next ()) + { + tmp = i.item (); + + // Right now we populate the global scope with all the CORBA basic + // types, so something like 'ULong' in an IDL file will find a + // match, unless we skip over these items. This is a workaround until + // there's time to fix the code generation for CORBA basic types. + if (!in_corba + && ACE_OS::strcmp (tmp->name ()->head ()->get_string (), "CORBA") == 0) { - add_to_referenced (d, - false, - 0); + continue; } - - // Now return what we have. - return d; - } - - // The name does not start with "::" - // Is name defined here? - long index = 0; - AST_Decl *first_one_found = 0; - while (true) - { - d = this->lookup_by_name_local (e->head (), - index, - full_def_only); - - if (0 == d) // Root of identifier not found in our local scope + + if (tmp->local_name ()->case_compare (e->head ())) { - // A no-op unless d can inherit. - d = look_in_inherited (e, treat_as_ref); - - if (0 == d) - { - // A no-op unless d can support interfaces. - d = look_in_supported (e, treat_as_ref); - } - - if ((0 == d) && in_parent) + d = tmp; + + if (e->length () == 1) { - if (full_def_only && (0 != first_one_found)) - { - // We don't need any diagnostic messages and we will - // not be following down the parent scope chain. - - return 0; - } - - // OK, not found. Go down parent scope chain. - d = ScopeAsDecl (this); - - if (d != 0) - { - s = d->defined_in (); - - if (0 == s) - { - d = 0; - } - else - { - d = s->lookup_by_name (e, - treat_as_ref, - in_parent, - full_def_only); - } - } - - if (0 != first_one_found) - { - // Since we have actually seen a match in local scope (even though that - // went nowhere) the full identifier is actually undefined as we are not - // allowed to follow down the parent scope chain. (The above is still - // useful to identify possible user scoping mistakes however for the - // following diagnostic.) - - if (0 != d) - { - ACE_ERROR (( - LM_ERROR, - ACE_TEXT ("%C: \"%C\", line %d: ") - ACE_TEXT ("Did you mean \"::%C\"\n") - ACE_TEXT (" declared at "), - idl_global->prog_name (), - idl_global->filename ()->get_string (), - idl_global->lineno (), - d->full_name ())); - - const bool same_file = - (0 == ACE_OS::strcmp ( - idl_global->filename ()->get_string (), - d->file_name ().c_str ()) ); - - if (!same_file) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("%C "), - d->file_name ().c_str () )); - } - - ACE_ERROR (( - LM_ERROR, - ACE_TEXT ("line %d but hidden by local \""), - d->line () )); - - if (ScopeAsDecl (this)->full_name ()[0]) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("::%C"), - ScopeAsDecl (this)->full_name () )); - } - - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("::%C\""), - e->head ()->get_string () )); - - const bool same_file_again = - (same_file && - 0 == ACE_OS::strcmp ( - idl_global->filename ()->get_string (), - first_one_found->file_name ().c_str ()) ); - - if (!same_file_again) - { - ACE_ERROR (( - LM_ERROR, - ACE_TEXT ("\n") - ACE_TEXT (" declared at %C "), - first_one_found->file_name ().c_str ())); - } - else - { - ACE_ERROR ((LM_ERROR, ACE_TEXT (" at ") )); - } - - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("line %d ?\n"), - first_one_found->line () )); - } - return 0; - } + d = this->local_checks (d, full_def_only); } - - // If treat_as_ref is true and d is not NULL, add d to - // set of nodes referenced here. - if (treat_as_ref && d != 0) + else { - t = AST_Type::narrow_from_decl (d); - - // Are we a type, rather than an identifier? - if (t != 0) + UTL_Scope *s = DeclAsScope (d); + + if (s != 0) { - // Are we defined in this scope or just referenced? - if (d->defined_in () == this) - { - UTL_Scope *ds = ScopeAsDecl (this)->defined_in (); - - if (ds != 0) - { - AST_Decl *parent = ScopeAsDecl (ds); - AST_Decl::NodeType nt = parent->node_type (); - - // If the scope we are defined in is itself - // inside a module, then we should also - // be exported to the enclosing scope, - // recursive until we get to the enclosing - // module (or root) scope. (CORBA 2.6 3.15.3). - while (nt != AST_Decl::NT_module - && nt != AST_Decl::NT_root) - { - ds->add_to_referenced (d, - false, - d->local_name ()); - - ds = parent->defined_in (); - parent = ScopeAsDecl (ds); - nt = parent->node_type (); - } - } - } + idl_global->masking_scopes ().enqueue_head (d); + + UTL_ScopedName *sn = + static_cast<UTL_ScopedName *> (e->tail ()); + + d = s->lookup_by_name_r (sn, full_def_only); } } - - // OK, now return whatever we found. - return d; - } - - // We have found the root of the identifier in our local scope. - first_one_found = d; - s = DeclAsScope (d); - - // OK, start of name is defined. Now loop doing local lookups - // of subsequent elements of the name, if any. - UTL_ScopedName *sn = (UTL_ScopedName *) e->tail (); - - if (sn != 0) - { - d = this->iter_lookup_by_name_local (d, - sn, - 0, - full_def_only); - } - - // If the start of the scoped name is an interface, and the - // above lookup failed, it's possible that what we're looking - // up was inherited into that interface. The first call to - // look_in_inherited() is this function only checks base classes - // of the scope (interface) we started the lookup from. - if (d == 0 && s != 0) - { - d = s->look_in_inherited (sn, treat_as_ref); - } - - // All OK, name fully resolved. - if (d != 0) - { - // If treat_as_ref is true and d is not 0, add d to - // set of nodes referenced here. - if (treat_as_ref) - { - add_to_referenced (d, false, 0); - } - - return d; } - else + } + + /// A rare enough case that it's worth it to separate it and + /// do it as a last resort. Catches anonymnous types, enums + /// and members with their types defined all in one statement. + for (UTL_ScopeActiveIterator i (this, UTL_Scope::IK_localtypes); + !i.is_done (); + i.next ()) + { + AST_Decl *tmp = i.item (); + + if (tmp->local_name ()->case_compare (e->head ())) { - ++index; + d = tmp; + break; } } + + if (d == 0) + { + d = this->special_lookup (e, full_def_only); + } + + return d; } -#endif + // Add a node to set of nodes referenced in this scope. void UTL_Scope::add_to_referenced (AST_Decl *e, @@ -2435,7 +2256,7 @@ UTL_Scope::iter_lookup_by_name_local (AST_Decl *d, } else { - result = sc->look_in_prev_mods (e->head (), true); + result = sc->look_in_prev_mods_local (e->head (), true); } UTL_ScopedName *sn = (UTL_ScopedName *) e->tail (); @@ -2468,6 +2289,48 @@ UTL_Scope::iter_lookup_by_name_local (AST_Decl *d, } } +AST_Decl * +UTL_Scope::local_checks (AST_Decl *d, bool full_def_only) +{ + AST_Decl *retval = 0; + AST_Decl::NodeType nt = d->node_type (); + + // Special case for forward declared types, + // In this case, we want to return + // the full definition member, whether defined yet or not. + // NOTE: corresponding full_definition fe_add_* methods + // depend on the behavior below! + if (nt == AST_Decl::NT_interface_fwd + || nt == AST_Decl::NT_valuetype_fwd + || nt == AST_Decl::NT_component_fwd + || nt == AST_Decl::NT_eventtype_fwd) + { + AST_Interface *i = + AST_InterfaceFwd::narrow_from_decl (d)->full_definition (); + + retval = (full_def_only && !i->is_defined () ? 0 : i); + } + else if (nt == AST_Decl::NT_struct_fwd + || nt == AST_Decl::NT_union_fwd) + { + AST_Structure *s = + AST_StructureFwd::narrow_from_decl (d)->full_definition (); + + retval = (full_def_only && !s->is_defined () ? 0 : s); + } + else if (AST_Template_Module_Ref::narrow_from_decl (d) == 0) + { + // If we are not a template module reference, ok. If so, + // however, we don't want to return that type, we want + // the regular module which will follow it immediately + // in this scope, return 0 and catch it on the nest + // iteration. + retval = d; + } + + return retval; +} + IMPL_NARROW_FROM_SCOPE(UTL_Scope) // UTL_SCOPE_ACTIVE_ITERATOR |