diff options
author | sma <sma@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2010-06-16 08:42:07 +0000 |
---|---|---|
committer | sma <sma@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2010-06-16 08:42:07 +0000 |
commit | 68f638b4765fdda7818f4a3c8bd1ee9dc9754473 (patch) | |
tree | f5e9052f7023d0ff7f5e593858e7d5e95a110f48 /TAO/TAO_IDL | |
parent | 50d718e350628d8cf9bcc26c6dbe32ab8ff0c8fb (diff) | |
download | ATCD-68f638b4765fdda7818f4a3c8bd1ee9dc9754473.tar.gz |
ChangeLogTag: Wed Jun 16 08:40:00 UTC 2010 Simon Massey <simon dot massey at prismtech dot com>
Diffstat (limited to 'TAO/TAO_IDL')
-rw-r--r-- | TAO/TAO_IDL/ast/ast_component_fwd.cpp | 6 | ||||
-rw-r--r-- | TAO/TAO_IDL/ast/ast_decl.cpp | 747 | ||||
-rw-r--r-- | TAO/TAO_IDL/ast/ast_generator.cpp | 97 | ||||
-rw-r--r-- | TAO/TAO_IDL/ast/ast_interface_fwd.cpp | 23 | ||||
-rw-r--r-- | TAO/TAO_IDL/ast/ast_module.cpp | 302 | ||||
-rw-r--r-- | TAO/TAO_IDL/ast/ast_structure_fwd.cpp | 23 | ||||
-rw-r--r-- | TAO/TAO_IDL/ast/ast_template_module_ref.cpp | 14 | ||||
-rw-r--r-- | TAO/TAO_IDL/be/be_generator.cpp | 71 | ||||
-rw-r--r-- | TAO/TAO_IDL/be/be_module.cpp | 12 | ||||
-rw-r--r-- | TAO/TAO_IDL/be_include/be_module.h | 2 | ||||
-rw-r--r-- | TAO/TAO_IDL/include/ast_component_fwd.h | 3 | ||||
-rw-r--r-- | TAO/TAO_IDL/include/ast_decl.h | 25 | ||||
-rw-r--r-- | TAO/TAO_IDL/include/ast_interface_fwd.h | 8 | ||||
-rw-r--r-- | TAO/TAO_IDL/include/ast_module.h | 43 | ||||
-rw-r--r-- | TAO/TAO_IDL/include/ast_structure_fwd.h | 8 | ||||
-rw-r--r-- | TAO/TAO_IDL/include/ast_template_module_ref.h | 8 | ||||
-rw-r--r-- | TAO/TAO_IDL/include/utl_scope.h | 2 | ||||
-rw-r--r-- | TAO/TAO_IDL/util/utl_scope.cpp | 630 |
18 files changed, 939 insertions, 1085 deletions
diff --git a/TAO/TAO_IDL/ast/ast_component_fwd.cpp b/TAO/TAO_IDL/ast/ast_component_fwd.cpp index cce1887ea04..1600774bdfd 100644 --- a/TAO/TAO_IDL/ast/ast_component_fwd.cpp +++ b/TAO/TAO_IDL/ast/ast_component_fwd.cpp @@ -47,4 +47,10 @@ AST_ComponentFwd::destroy (void) this->AST_InterfaceFwd::destroy (); } +bool +AST_ComponentFwd::is_fwd (void) +{ + return true; // This is a fwd declared type +} + IMPL_NARROW_FROM_DECL (AST_ComponentFwd) diff --git a/TAO/TAO_IDL/ast/ast_decl.cpp b/TAO/TAO_IDL/ast/ast_decl.cpp index 8d9588d811f..62d44915e10 100644 --- a/TAO/TAO_IDL/ast/ast_decl.cpp +++ b/TAO/TAO_IDL/ast/ast_decl.cpp @@ -101,6 +101,15 @@ COMMON_Base::COMMON_Base (bool local, { } +COMMON_Base::~COMMON_Base (void) +{ +} + +void +COMMON_Base::destroy (void) +{ +} + bool COMMON_Base::is_local (void) { @@ -125,11 +134,6 @@ COMMON_Base::is_abstract (bool val) this->is_abstract_ = val; } -void -COMMON_Base::destroy (void) -{ -} - AST_Decl::AST_Decl (NodeType nt, UTL_ScopedName *n, bool anonymous) @@ -145,7 +149,7 @@ AST_Decl::AST_Decl (NodeType nt, pd_node_type (nt), pd_line (idl_global->lineno ()), pd_name (0), - pd_local_name (n == 0 ? 0 : n->last_component ()->copy ()), + pd_local_name (n ? n->last_component ()->copy () : 0), pd_original_local_name (0), full_name_ (0), prefix_ (0), @@ -157,33 +161,87 @@ AST_Decl::AST_Decl (NodeType nt, { // If this is the root node, the filename won't have been set yet. UTL_String *fn = idl_global->filename (); - this->pd_file_name = (fn != 0 ? fn->get_string () : ""); + this->pd_file_name = (fn ? fn->get_string () : ""); this->compute_full_name (n); char *prefix = 0; idl_global->pragma_prefixes ().top (prefix); + this->prefix_ = ACE::strnew (prefix ? prefix : ""); - if (prefix == 0) + if (n) { - this->prefix_ = ACE::strnew (""); + // The function body creates its own copy. + this->original_local_name (n->last_component ()); } - else + + this->compute_repoID (); +} + +AST_Decl::~AST_Decl (void) +{ +} + +void +AST_Decl::destroy (void) +{ + // These are not set for the root node. + if (this->pd_name) { - this->prefix_ = ACE::strnew (prefix); + this->pd_name->destroy (); + delete this->pd_name; + this->pd_name = 0; } - if (n != 0) + if (this->pd_local_name) { - // The function body creates its own copy. - this->original_local_name (n->last_component ()); + this->pd_local_name->destroy (); + delete this->pd_local_name; + this->pd_local_name = 0; } - this->compute_repoID (); + if (this->pd_original_local_name) + { + this->pd_original_local_name->destroy (); + delete this->pd_original_local_name; + this->pd_original_local_name = 0; + } + + if (this->last_referenced_as_) + { + this->last_referenced_as_->destroy (); + delete this->last_referenced_as_; + this->last_referenced_as_ = 0; + } + + delete [] this->full_name_; + this->full_name_ = 0; + + delete [] this->repoID_; + this->repoID_ = 0; + + delete [] this->prefix_; + this->prefix_ = 0; + + delete [] this->version_; + this->version_ = 0; + + delete [] this->flat_name_; + this->flat_name_ = 0; } -AST_Decl::~AST_Decl (void) +AST_Decl * +AST_Decl::adjust_found ( + bool /*ignore_fwd*/, + bool /*full_def_only*/) +{ + return this; // Defaults to no adjustment +} + +bool +AST_Decl::is_fwd (void) { + return false; // Not a fwd declared type (by default) } // Private operations. @@ -195,55 +253,48 @@ AST_Decl::compute_full_name (UTL_ScopedName *n) // This should happen only when we are a non-void predefined type, // in which case our scoped name has already been created by the // AST_PredefinedType constructor. - if (n == 0) + if (!n) { return; } - UTL_ScopedName *cn = 0; - AST_Decl *d = 0; - - // Initialize this name to 0. - this->pd_name = 0; - // Global scope? - if (this->defined_in () == 0) + if (!this->defined_in ()) { this->pd_name = (UTL_IdList *) n->copy (); return; } + // Initialize this name to 0. + this->pd_name = 0; + // OK, not global. So copy name of containing scope, then // smash last cdr of copy with new component - d = ScopeAsDecl (this->defined_in ()); - - if (d != 0) + UTL_ScopedName *cn = 0; + AST_Decl *d = ScopeAsDecl (this->defined_in ()); + if (d) { cn = d->name (); + if (cn) + { + this->pd_name = (UTL_IdList *) cn->copy (); + } } - if (cn != 0) - { - this->pd_name = (UTL_IdList *) cn->copy (); - } - - if (this->pd_local_name != 0) + if (this->pd_local_name) { - if (this->pd_name == 0) - { - ACE_NEW (this->pd_name, - UTL_ScopedName (this->pd_local_name->copy (), - 0)); - } - else + if (this->pd_name) { UTL_ScopedName *conc_name = 0; ACE_NEW (conc_name, - UTL_ScopedName (this->pd_local_name->copy (), - 0)); - + UTL_ScopedName (this->pd_local_name->copy (), 0)); this->pd_name->nconc (conc_name); } + else + { + ACE_NEW (this->pd_name, + UTL_ScopedName (this->pd_local_name->copy (), 0)); + } } } @@ -256,13 +307,11 @@ AST_Decl::set_prefix_with_typeprefix_r (const char *value, return; } - if (this->prefix_scope_ != 0) + if (this->prefix_scope_) { AST_Decl *decl = ScopeAsDecl (this->prefix_scope_); - bool const overridden = decl->has_ancestor (ScopeAsDecl (appeared_in)); - if (overridden) { return; @@ -275,26 +324,18 @@ AST_Decl::set_prefix_with_typeprefix_r (const char *value, this->prefix_scope_ = appeared_in; UTL_Scope *s = DeclAsScope (this); - - if (s != 0) + if (s) { - AST_Decl *tmp = 0; - UTL_Scope *s_tmp = 0; - for (UTL_ScopeActiveIterator i (s, UTL_Scope::IK_decls); !i.is_done (); i.next ()) { - tmp = i.item (); - s_tmp = DeclAsScope (tmp); - - if (s_tmp == 0) + AST_Decl *tmp = i.item (); + UTL_Scope *s_tmp = DeclAsScope (tmp); + if (s_tmp) { - continue; + tmp->set_prefix_with_typeprefix_r (value, appeared_in); } - - tmp->set_prefix_with_typeprefix_r (value, - appeared_in); } } @@ -302,27 +343,17 @@ AST_Decl::set_prefix_with_typeprefix_r (const char *value, if (this->node_type () == AST_Decl::NT_module) { AST_Module *m = AST_Module::narrow_from_decl (this); - - for (ACE_Unbounded_Set_Iterator<AST_Module *> iter (m->prev_mods ()); - !iter.done (); - iter.advance ()) + while (!!(m = m->previous_opening ())) { - AST_Module **m = 0; - iter.next (m); - - for (UTL_ScopeActiveIterator si (*m, UTL_Scope::IK_decls); + for (UTL_ScopeActiveIterator si (m, UTL_Scope::IK_decls); !si.is_done (); si.next ()) { AST_Decl *d = si.item (); - - if (d->node_type () == AST_Decl::NT_pre_defined) + if (d->node_type () != AST_Decl::NT_pre_defined) { - continue; + d->set_prefix_with_typeprefix_r (value, appeared_in); } - - d->set_prefix_with_typeprefix_r (value, - appeared_in); } } } @@ -336,11 +367,7 @@ AST_Decl::set_prefix_with_typeprefix_r (const char *value, void AST_Decl::compute_full_name (void) { - if (this->full_name_ != 0) - { - return; - } - else + if (!this->full_name_) { size_t namelen = 0; long first = true; @@ -363,10 +390,9 @@ AST_Decl::compute_full_name (void) // Print the identifier. name = i.item ()->get_string (); namelen += ACE_OS::strlen (name); - if (first) { - if (ACE_OS::strcmp (name, "") != 0) + if (ACE_OS::strcmp (name, "")) { // Does not start with a "". first = false; @@ -378,10 +404,8 @@ AST_Decl::compute_full_name (void) } } - ACE_NEW (this->full_name_, - char[namelen + 1]); - - this->full_name_[0] = '\0'; + ACE_NEW (this->full_name_, char [namelen + 1]); + this->full_name_ [0] = '\0'; first = true; second = false; @@ -401,10 +425,9 @@ AST_Decl::compute_full_name (void) // Print the identifier. name = j.item ()->get_string (); ACE_OS::strcat (this->full_name_, name); - if (first) { - if (ACE_OS::strcmp (name, "") != 0) + if (ACE_OS::strcmp (name, "")) { // Does not start with a "". first = false; @@ -422,7 +445,7 @@ AST_Decl::compute_full_name (void) void AST_Decl::compute_repoID (void) { - if (this->repoID_ != 0) + if (this->repoID_) { return; } @@ -436,10 +459,9 @@ AST_Decl::compute_repoID (void) const char *parent_prefix = 0; // If our prefix is empty, we check to see if an ancestor has one. - while (ACE_OS::strcmp (prefix, "") == 0 && scope != 0) + while (scope && !ACE_OS::strcmp (prefix, "")) { AST_Decl *parent = ScopeAsDecl (scope); - if (parent->node_type () == AST_Decl::NT_root && parent->imported ()) { @@ -458,14 +480,14 @@ AST_Decl::compute_repoID (void) scope = this->defined_in (); // If our version is has not bee set, we use the parent's, if any. - while (version == 0 && scope != 0) + while (!version && scope) { AST_Decl *parent = ScopeAsDecl (scope); version = parent->version_; scope = parent->defined_in (); } - if (version != 0) + if (version) { // Version member string + ':' namelen += ACE_OS::strlen (version) + 1; @@ -504,7 +526,7 @@ AST_Decl::compute_repoID (void) if (first) { - if (ACE_OS::strcmp (name, "") != 0) + if (ACE_OS::strcmp (name, "")) { // Does not start with a "". first = false; @@ -516,20 +538,12 @@ AST_Decl::compute_repoID (void) } } - ACE_NEW (this->repoID_, - char[namelen + 1]); + ACE_NEW (this->repoID_, char [namelen + 1]); + ACE_OS::sprintf (this->repoID_, "IDL:"); - this->repoID_[0] = '\0'; - - ACE_OS::sprintf (this->repoID_, - "%s", - "IDL:"); - - if (ACE_OS::strcmp (prefix, "") != 0) + if (ACE_OS::strcmp (prefix, "")) { - ACE_OS::strcat (this->repoID_, - prefix); - + ACE_OS::strcat (this->repoID_, prefix); ACE_OS::strcat (this->repoID_, "/"); } @@ -559,13 +573,12 @@ AST_Decl::compute_repoID (void) } else { - ACE_OS::strcat (this->repoID_, - name); + ACE_OS::strcat (this->repoID_, name); } if (first) { - if (ACE_OS::strcmp (name, "") != 0) + if (ACE_OS::strcmp (name, "")) { // Does not start with a "". first = false; @@ -577,17 +590,14 @@ AST_Decl::compute_repoID (void) } } - if (version != 0) + if (version) { - ACE_OS::strcat (this->repoID_, - ":"); - ACE_OS::strcat (this->repoID_, - version); + ACE_OS::strcat (this->repoID_, ":"); + ACE_OS::strcat (this->repoID_, version); } else { - ACE_OS::strcat (this->repoID_, - ":1.0"); + ACE_OS::strcat (this->repoID_, ":1.0"); } } @@ -608,11 +618,7 @@ AST_Decl::flat_name (void) void AST_Decl::compute_flat_name (void) { - if (this->flat_name_ != 0) - { - return; - } - else + if (!this->flat_name_) { size_t namelen = 0; long first = true; @@ -642,7 +648,7 @@ AST_Decl::compute_flat_name (void) if (first) { - if (ACE_OS::strcmp (item_name, "") != 0) + if (ACE_OS::strcmp (item_name, "")) { // Does not start with a "". first = false; @@ -652,16 +658,14 @@ AST_Decl::compute_flat_name (void) second = true; } } - + tmp->destroy (); delete tmp; tmp = 0; } - ACE_NEW (this->flat_name_, - char[namelen + 1]); - - this->flat_name_[0] = '\0'; + ACE_NEW (this->flat_name_, char [namelen + 1]); + this->flat_name_ [0] = '\0'; first = true; second = false; @@ -687,7 +691,7 @@ AST_Decl::compute_flat_name (void) if (first) { - if (ACE_OS::strcmp (item_name, "") != 0) + if (ACE_OS::strcmp (item_name, "")) { // Does not start with a "". first = false; @@ -710,78 +714,106 @@ AST_Decl::node_type_to_string (NodeType nt) { switch (nt) { - case NT_module: - return "module"; - case NT_interface: - case NT_interface_fwd: - return "interface"; - case NT_valuetype: - case NT_valuetype_fwd: - case NT_valuebox: - return "valuetype"; - case NT_const: - return "const"; - case NT_except: - return "exception"; - case NT_attr: - return "attribute"; - case NT_union: - case NT_union_fwd: - return "union"; - case NT_struct: - case NT_struct_fwd: - return "struct"; - case NT_enum: - return "enum"; - case NT_string: - return "string"; - case NT_wstring: - return "wstring"; - case NT_array: - return "array"; - case NT_sequence: - return "sequence"; - case NT_typedef: - return "typedef"; - case NT_pre_defined: - return "primitive"; - case NT_native: - return "native"; - case NT_factory: - return "factory"; - case NT_component: - case NT_component_fwd: - return "component"; - case NT_home: - return "home"; - case NT_eventtype: - case NT_eventtype_fwd: - return "eventtype"; - case NT_type: - return "typename"; - case NT_fixed: - return "fixed"; - case NT_porttype: - return "porttype"; - case NT_provides: - return "provides"; - case NT_uses: - return "uses"; - case NT_publishes: - return "publishes"; - case NT_emits: - return "emits"; - case NT_consumes: - return "consumes"; - // No useful output for these. - case NT_enum_val: - case NT_field: - case NT_union_branch: - case NT_op: - case NT_argument: - case NT_root: - default: - return ""; + case NT_module: + return "module"; + + case NT_interface: + case NT_interface_fwd: + return "interface"; + + case NT_valuetype: + case NT_valuetype_fwd: + case NT_valuebox: + return "valuetype"; + + case NT_const: + return "const"; + + case NT_except: + return "exception"; + + case NT_attr: + return "attribute"; + + case NT_union: + case NT_union_fwd: + return "union"; + + case NT_struct: + case NT_struct_fwd: + return "struct"; + + case NT_enum: + return "enum"; + + case NT_string: + return "string"; + + case NT_wstring: + return "wstring"; + + case NT_array: + return "array"; + + case NT_sequence: + return "sequence"; + + case NT_typedef: + return "typedef"; + + case NT_pre_defined: + return "primitive"; + + case NT_native: + return "native"; + + case NT_factory: + return "factory"; + + case NT_component: + case NT_component_fwd: + return "component"; + + case NT_home: + return "home"; + + case NT_eventtype: + case NT_eventtype_fwd: + return "eventtype"; + + case NT_type: + return "typename"; + + case NT_fixed: + return "fixed"; + + case NT_porttype: + return "porttype"; + + case NT_provides: + return "provides"; + + case NT_uses: + return "uses"; + + case NT_publishes: + return "publishes"; + + case NT_emits: + return "emits"; + + case NT_consumes: + return "consumes"; + + // No useful output for these. + case NT_enum_val: + case NT_field: + case NT_union_branch: + case NT_op: + case NT_argument: + case NT_root: + default: + return ""; } } @@ -790,44 +822,32 @@ AST_Decl::node_type_to_string (NodeType nt) bool AST_Decl::has_ancestor (AST_Decl *s) { - if (this == s) + AST_Decl *work = this; + do { - return true; - } - - AST_Module *m = AST_Module::narrow_from_decl (s); - - if (m != 0) - { - ACE_Unbounded_Set<AST_Module *> &prev = m->prev_mods (); + if (work == s) + { + return true; + } - for (ACE_Unbounded_Set<AST_Module *>::CONST_ITERATOR i (prev); - !i.done (); - i.advance ()) + AST_Module *m = AST_Module::narrow_from_decl (s); + if (m) { - AST_Module **mm = 0; - i.next (mm); - - for (UTL_ScopeActiveIterator si (*mm, UTL_Scope::IK_decls); - !si.is_done (); - si.next ()) + while (!!(m = m->previous_opening ())) { - AST_Decl *d = si.item (); - - if (this == d) + if (static_cast<AST_Decl *> (m) == s) { return true; } } } - } - if (this->pd_defined_in == 0) - { - return false; - } + work = work->pd_defined_in ? + ScopeAsDecl (work->pd_defined_in) : + 0; + } while (work); - return ScopeAsDecl (this->pd_defined_in)->has_ancestor (s); + return false; } bool @@ -836,13 +856,12 @@ AST_Decl::is_child (AST_Decl *s) if (this->defined_in ()) { AST_Decl *d = ScopeAsDecl (this->defined_in ()); - - if (d == 0) + if (!d) { return 0; } - if (ACE_OS::strcmp (d->full_name (), s->full_name ()) == 0) + if (!ACE_OS::strcmp (d->full_name (), s->full_name ())) { return 1; } @@ -858,12 +877,7 @@ AST_Decl::is_nested (void) // If we have an outermost scope and if that scope is not that of the Root, // then we are defined at some nesting level. - if (d != 0 && d->node_type () != AST_Decl::NT_root) - { - return true; - } - - return false; + return (d && d->node_type () != AST_Decl::NT_root); } // Dump this AST_Decl to the ostream o. @@ -887,60 +901,12 @@ AST_Decl::ast_accept (ast_visitor *visitor) return visitor->visit_decl (this); } -void -AST_Decl::destroy (void) -{ - // These are not set for the root node. - if (this->pd_name != 0) - { - this->pd_name->destroy (); - delete this->pd_name; - this->pd_name = 0; - } - - if (this->pd_local_name != 0) - { - this->pd_local_name->destroy (); - delete this->pd_local_name; - this->pd_local_name = 0; - } - - if (this->pd_original_local_name != 0) - { - this->pd_original_local_name->destroy (); - delete this->pd_original_local_name; - this->pd_original_local_name = 0; - } - - if (this->last_referenced_as_ != 0) - { - this->last_referenced_as_->destroy (); - delete this->last_referenced_as_; - this->last_referenced_as_ = 0; - } - - delete [] this->full_name_; - this->full_name_ = 0; - - delete [] this->repoID_; - this->repoID_ = 0; - - delete [] this->prefix_; - this->prefix_ = 0; - - delete [] this->version_; - this->version_ = 0; - - delete [] this->flat_name_; - this->flat_name_ = 0; -} - // Data accessors. const char * AST_Decl::full_name (void) { - if (this->full_name_ == 0) + if (!this->full_name_) { this->compute_full_name (); } @@ -957,7 +923,7 @@ AST_Decl::repoID (void) this->repoID_ = ACE::strnew (""); } - if (this->repoID_ == 0) + if (!this->repoID_) { this->compute_repoID (); } @@ -968,11 +934,7 @@ AST_Decl::repoID (void) void AST_Decl::repoID (char *value) { - if (this->repoID_ != 0) - { - delete [] this->repoID_; - } - + delete [] this->repoID_; this->repoID_ = value; } @@ -992,7 +954,7 @@ AST_Decl::prefix (const char *value) const char * AST_Decl::version (void) { - if (this->version_ == 0) + if (!this->version_) { // Calling the method will compute if necessary. const char *repo_id = this->repoID (); @@ -1002,19 +964,17 @@ AST_Decl::version (void) const char *tail1 = 0; const char *tail2 = 0; - if (repo_id != 0) + if (repo_id) { - tail1 = ACE_OS::strchr (repo_id, - ':'); + tail1 = ACE_OS::strchr (repo_id, ':'); } - if (tail1 != 0) + if (tail1) { - tail2 = ACE_OS::strchr (tail1 + 1, - ':'); + tail2 = ACE_OS::strchr (tail1 + 1, ':'); } - if (! this->typeid_set_ && tail2 != 0) + if (!this->typeid_set_ && tail2) { this->version_ = ACE::strnew (tail2 + 1); } @@ -1031,19 +991,18 @@ void AST_Decl::version (char *value) { // Previous #pragma version or #pragma id make this illegal. - if ((this->version_ == 0 || ACE_OS::strcmp (this->version_, value) == 0) - && ! this->typeid_set_) + if ((!this->version_ || !ACE_OS::strcmp (this->version_, value)) + && !this->typeid_set_) { delete [] this->version_; this->version_ = value; // Repo id is now computed eagerly, so a version set must update // is as well. - if (this->repoID_ != 0) + if (this->repoID_) { ACE_CString tmp (this->repoID_); ACE_CString::size_type const pos = tmp.rfind (':'); - if (pos != ACE_CString::npos) { tmp = tmp.substr (0, pos + 1) + value; @@ -1088,30 +1047,29 @@ AST_Decl::set_id_with_typeid (char *value) // Can't call 'typeid' twice, even with the same value. if (this->typeid_set ()) { - idl_global->err ()->error1 (UTL_Error::EIDL_TYPEID_RESET, - this); + idl_global->err ()->error1 (UTL_Error::EIDL_TYPEID_RESET, this); } // Are we a legal type for 'typeid'? switch (this->pd_node_type) - { + { case AST_Decl::NT_field: { AST_Decl::NodeType nt = ScopeAsDecl (this->defined_in ())->node_type (); - if (nt == AST_Decl::NT_valuetype || nt == AST_Decl::NT_eventtype) + if ( nt == AST_Decl::NT_valuetype + || nt == AST_Decl::NT_eventtype) { break; } else { - idl_global->err ()->error1 (UTL_Error::EIDL_INVALID_TYPEID, - this); - + idl_global->err ()->error1 (UTL_Error::EIDL_INVALID_TYPEID, this); return; } } + case AST_Decl::NT_module: case AST_Decl::NT_interface: case AST_Decl::NT_const: @@ -1125,12 +1083,11 @@ AST_Decl::set_id_with_typeid (char *value) case AST_Decl::NT_home: case AST_Decl::NT_eventtype: break; - default: - idl_global->err ()->error1 (UTL_Error::EIDL_INVALID_TYPEID, - this); + default: + idl_global->err ()->error1 (UTL_Error::EIDL_INVALID_TYPEID, this); return; - } + } delete [] this->repoID_; this->repoID_ = 0; @@ -1144,7 +1101,7 @@ AST_Decl::set_prefix_with_typeprefix (const char *value) // Are we a legal type for 'typeprefix'? This is checked only at // the top level. switch (this->pd_node_type) - { + { case AST_Decl::NT_module: case AST_Decl::NT_interface: case AST_Decl::NT_valuetype: @@ -1153,15 +1110,13 @@ AST_Decl::set_prefix_with_typeprefix (const char *value) case AST_Decl::NT_union: case AST_Decl::NT_except: break; - default: - idl_global->err ()->error1 (UTL_Error::EIDL_INVALID_TYPEPREFIX, - this); + default: + idl_global->err ()->error1 (UTL_Error::EIDL_INVALID_TYPEPREFIX, this); return; - } + } - this->set_prefix_with_typeprefix_r (value, - DeclAsScope (this)); + this->set_prefix_with_typeprefix_r (value, DeclAsScope (this)); } bool @@ -1245,13 +1200,11 @@ UTL_ScopedName * AST_Decl::compute_name (const char *prefix, const char *suffix) { - if (prefix == 0 || suffix == 0) + if (!prefix || !suffix) { return 0; } - UTL_ScopedName *result_name = 0; - // Prepare prefix_<local_name>_suffix string. ACE_CString suffix_str (suffix); @@ -1270,12 +1223,12 @@ AST_Decl::compute_name (const char *prefix, // UTL_Scoped name for the resulting local name. UTL_ScopedName *result_local_name = 0; ACE_NEW_RETURN (result_local_name, - UTL_ScopedName (result_local_id, - 0), + UTL_ScopedName (result_local_id, 0), 0); // Global scope? - if (this->defined_in () == 0) + UTL_ScopedName *result_name = 0; + if (!this->defined_in ()) { result_name = result_local_name; } @@ -1285,22 +1238,19 @@ AST_Decl::compute_name (const char *prefix, // smash last cdr of copy with new component. AST_Decl *d = ScopeAsDecl (this->defined_in ()); - - if (d != 0) + if (d) { UTL_ScopedName *cn = d->name (); - - if (cn != 0) + if (cn) { result_name = (UTL_ScopedName *) cn->copy (); - - if (result_name == 0) + if (result_name) { - result_name = result_local_name; + result_name->nconc (result_local_name); } else { - result_name->nconc (result_local_name); + result_name = result_local_name; } } } @@ -1317,17 +1267,16 @@ AST_Decl::set_name (UTL_ScopedName *n) return; } - if (this->pd_name != 0) + if (this->pd_name) { this->pd_name->destroy (); delete this->pd_name; } this->pd_name = n; - - if (n != 0) + if (n) { - if (this->pd_local_name != 0) + if (this->pd_local_name) { this->pd_local_name->destroy (); delete this->pd_local_name; @@ -1336,7 +1285,7 @@ AST_Decl::set_name (UTL_ScopedName *n) this->pd_local_name = n->last_component ()->copy (); // The name without _cxx_ prefix removed, if there was any. - if (this->pd_original_local_name != 0) + if (this->pd_original_local_name) { this->pd_original_local_name->destroy (); delete this->pd_original_local_name; @@ -1365,7 +1314,7 @@ AST_Decl::local_name (void) void AST_Decl::local_name (Identifier *id) { - if (this->pd_local_name != 0) + if (this->pd_local_name) { this->pd_local_name->destroy (); } @@ -1378,7 +1327,7 @@ Identifier * AST_Decl::compute_local_name (const char *prefix, const char *suffix) { - if (prefix == 0 || suffix == 0) + if (!prefix || !suffix) { return 0; } @@ -1410,8 +1359,7 @@ void AST_Decl::original_local_name (Identifier *local_name) { // Remove _cxx_ if it is present. - if (ACE_OS::strstr (local_name->get_string (), - "_cxx_") + if (ACE_OS::strstr (local_name->get_string (), "_cxx_") == local_name->get_string ()) { // AACE_CString class is good to do this stuff. @@ -1453,7 +1401,7 @@ AST_Decl::last_referenced_as (void) const void AST_Decl::last_referenced_as (UTL_ScopedName *n) { - if (this->last_referenced_as_ != 0) + if (this->last_referenced_as_) { this->last_referenced_as_->destroy (); } @@ -1482,51 +1430,53 @@ AST_Decl::contains_wstring (void) { switch (this->node_type ()) { - case AST_Decl::NT_array: - { - AST_Array *a = AST_Array::narrow_from_decl (this); - this->contains_wstring_ = - a->base_type ()->contains_wstring (); - break; - } - case AST_Decl::NT_except: - case AST_Decl::NT_struct: - case AST_Decl::NT_union: - { - AST_Structure *s = AST_Structure::narrow_from_decl (this); - this->contains_wstring_ = - s->contains_wstring (); - break; - } - case AST_Decl::NT_sequence: - { - AST_Sequence *s = AST_Sequence::narrow_from_decl (this); - this->contains_wstring_ = - s->base_type ()->contains_wstring (); - break; - } - case AST_Decl::NT_attr: - case AST_Decl::NT_field: - case AST_Decl::NT_union_branch: - { - AST_Field *f = AST_Field::narrow_from_decl (this); - this->contains_wstring_ = - f->field_type ()->contains_wstring (); - break; - } - case AST_Decl::NT_typedef: - { - AST_Typedef *td = AST_Typedef::narrow_from_decl (this); - this->contains_wstring_ = - td->primitive_base_type ()->contains_wstring (); - break; - } - case AST_Decl::NT_wstring: - this->contains_wstring_ = 1; + case AST_Decl::NT_array: + { + AST_Array *a = AST_Array::narrow_from_decl (this); + this->contains_wstring_ = a->base_type ()->contains_wstring (); + break; + } + + case AST_Decl::NT_except: + case AST_Decl::NT_struct: + case AST_Decl::NT_union: + { + AST_Structure *s = AST_Structure::narrow_from_decl (this); + this->contains_wstring_ = s->contains_wstring (); + break; + } + + case AST_Decl::NT_sequence: + { + AST_Sequence *s = AST_Sequence::narrow_from_decl (this); + this->contains_wstring_ = s->base_type ()->contains_wstring (); + break; + } + + case AST_Decl::NT_attr: + case AST_Decl::NT_field: + case AST_Decl::NT_union_branch: + { + AST_Field *f = AST_Field::narrow_from_decl (this); + this->contains_wstring_ = f->field_type ()->contains_wstring (); break; - default: - this->contains_wstring_ = 0; + } + + case AST_Decl::NT_typedef: + { + AST_Typedef *td = AST_Typedef::narrow_from_decl (this); + this->contains_wstring_ = + td->primitive_base_type ()->contains_wstring (); break; + } + + case AST_Decl::NT_wstring: + this->contains_wstring_ = 1; + break; + + default: + this->contains_wstring_ = 0; + break; } } @@ -1549,31 +1499,24 @@ AST_Decl::masking_checks (AST_Decl *mod) } 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) + if (me_mod) { - for (ACE_Unbounded_Set<AST_Module *>::CONST_ITERATOR i ( - of_mod->prev_mods ()); - !i.done (); - i.advance ()) + AST_Module *po_mod = AST_Module::narrow_from_decl (mod); + if (po_mod) { - AST_Module **m = 0; - i.next (m); - - if (*m == me_mod) + while (!!(po_mod = po_mod->previous_opening ())) { - return true; + if (po_mod == 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 4d9d631e449..d490aa13622 100644 --- a/TAO/TAO_IDL/ast/ast_generator.cpp +++ b/TAO/TAO_IDL/ast/ast_generator.cpp @@ -119,8 +119,7 @@ AST_Generator::create_predefined_type (AST_PredefinedType::PredefinedType t, { AST_PredefinedType *retval = 0; ACE_NEW_RETURN (retval, - AST_PredefinedType (t, - n), + AST_PredefinedType (t, n), 0); return retval; @@ -130,73 +129,55 @@ AST_Module * AST_Generator::create_module (UTL_Scope *s, UTL_ScopedName *n) { - // 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; - ACE_NEW_RETURN (retval, - AST_Module (n), - 0); - AST_Module *m = 0; - - // Check for another module of the same name in this scope. + // Check for another module of the same name in the scope. for (UTL_ScopeActiveIterator iter (s, UTL_Scope::IK_decls); !iter.is_done (); iter.next ()) { // 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 (m != 0) + AST_Module *m = AST_Module::narrow_from_decl (iter.item ()); + if (m && m->local_name ()->compare (n->last_component ())) { - // Does it have the same name as the one we're - // supposed to create. - if (m->local_name ()->compare (n->last_component ())) - { - // 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 ())); - } + // Create this new module with referance to the + // "first" previous module found in scope. + ACE_NEW_RETURN (retval, AST_Module (n, m), 0); + retval->prefix (const_cast<char *> (m->prefix ())); + return retval; } } - // If this scope is itself a module, and has been previously - // opened, the previous opening may contain a previous opening + // Since the scope didn't contain the same module name, it + // doesn't mean that we haven't see it before. If the scope + // is itself a module, and has been previously opened, any + // of the previous openings may contain a previous opening // of the module we're creating. - m = AST_Module::narrow_from_scope (s); - - if (m != 0) + // AST_Module *prev_module = AST_Module::narrow_from_scope (s); + AST_Module *prev_module = AST_Module::narrow_from_scope (s); + if (prev_module) { - for (ACE_Unbounded_Set<AST_Module *>::CONST_ITERATOR i ( - m->prev_mods ()); - !i.done (); - i.advance ()) + while (!!(prev_module= prev_module->previous_opening ())) { - AST_Module **mm = 0; - i.next (mm); - - for (UTL_ScopeActiveIterator si (*mm, UTL_Scope::IK_decls); - !si.is_done (); - si.next ()) + for (UTL_ScopeActiveIterator iter (prev_module, UTL_Scope::IK_decls); + !iter.is_done (); + iter.next ()) { - AST_Decl *d = si.item (); - - if (retval->local_name ()->case_compare (d->local_name ())) + AST_Module *m = AST_Module::narrow_from_decl (iter.item ()); + if (m && m->local_name ()->compare (n->last_component ())) { - m = AST_Module::narrow_from_decl (d); - - if (m != 0) - { - retval->add_to_previous (m); - } + // Create this new module with referance to the + // "first" previous module found in scope. + ACE_NEW_RETURN (retval, AST_Module (n, m), 0); + return retval; } } } } + // There is no previous module to this one + ACE_NEW_RETURN (retval, AST_Module (n), 0); return retval; } @@ -239,18 +220,17 @@ AST_Generator::create_interface_fwd (UTL_ScopedName *n, bool is_local, bool is_abstract) { - AST_Interface *full_defn = this->create_interface (n, - 0, - -1, - 0, - 0, - is_local, - is_abstract); - + AST_Interface + *full_defn = this->create_interface (n, + 0, + -1, + 0, + 0, + is_local, + is_abstract); AST_InterfaceFwd *retval = 0; ACE_NEW_RETURN (retval, - AST_InterfaceFwd (full_defn, - n), + AST_InterfaceFwd (full_defn, n), 0); full_defn->fwd_decl (retval); @@ -289,8 +269,7 @@ AST_Generator::create_valuetype (UTL_ScopedName *n, // The following helps with OBV_ namespace generation. AST_Module *m = AST_Module::narrow_from_scope (retval->defined_in ()); - - if (m != 0) + if (m) { m->set_has_nested_valuetype (); } diff --git a/TAO/TAO_IDL/ast/ast_interface_fwd.cpp b/TAO/TAO_IDL/ast/ast_interface_fwd.cpp index 29b8d3b6286..7b68c4f3e9a 100644 --- a/TAO/TAO_IDL/ast/ast_interface_fwd.cpp +++ b/TAO/TAO_IDL/ast/ast_interface_fwd.cpp @@ -282,4 +282,27 @@ AST_InterfaceFwd::destroy (void) this->AST_Type::destroy (); } +bool +AST_InterfaceFwd::is_fwd (void) +{ + return true; // This is a fwd declared type +} + +// We don't actually want the forward declaration, +// but want to return the full definition member, +// whether defined yet or not. +AST_Decl * +AST_InterfaceFwd::adjust_found ( + bool ignore_fwd, + bool full_def_only) +{ + if (ignore_fwd) + { + AST_Interface *i = this->full_definition (); + return (full_def_only && !i->is_defined () ? 0 : i); + } + + return this; +} + IMPL_NARROW_FROM_DECL (AST_InterfaceFwd) diff --git a/TAO/TAO_IDL/ast/ast_module.cpp b/TAO/TAO_IDL/ast/ast_module.cpp index bd543a996aa..b1f5d3448c0 100644 --- a/TAO/TAO_IDL/ast/ast_module.cpp +++ b/TAO/TAO_IDL/ast/ast_module.cpp @@ -102,23 +102,39 @@ trademarks or registered trademarks of Sun Microsystems, Inc. #include "nr_extern.h" AST_Decl::NodeType const -AST_Module::NT = AST_Decl::NT_module; + AST_Module::NT = AST_Decl::NT_module; -bool AST_Module::in_prev_ = false; - -AST_Module::AST_Module (UTL_ScopedName *n) - : AST_Decl (AST_Decl::NT_module, - n), - UTL_Scope (AST_Decl::NT_module), - pd_has_nested_valuetype (0), - from_inst_ (0) +AST_Module::AST_Module (UTL_ScopedName *n, AST_Module *previous) + : AST_Decl (AST_Decl::NT_module, n), + UTL_Scope (AST_Decl::NT_module), + pd_has_nested_valuetype_ (0), + previous_opening_ (previous), + last_in_same_parent_scope_ (this), + from_inst_ (0) { + // NOTE previous passed into this constructor should be + // the FIRST module that is a previous opening of this same + // module in the scope in which it is stored. Later on if + // the module is validated and added to it's scope, the + // previous_opening_ will be adjusted to be the immediatly + // previous opening of this module. See fe_add_module () + // below. } AST_Module::~AST_Module (void) { } +void +AST_Module::destroy (void) +{ + this->UTL_Scope::destroy (); + this->AST_Decl::destroy (); +} + +IMPL_NARROW_FROM_DECL(AST_Module) +IMPL_NARROW_FROM_SCOPE(AST_Module) + // Dump this AST_Module node to the ostream o. void AST_Module::dump (ACE_OSTREAM_TYPE &o) @@ -131,30 +147,38 @@ AST_Module::dump (ACE_OSTREAM_TYPE &o) this->dump_i (o, "}"); } +// We actually want to match the LAST module found in +// the scope being searched not the FIRST one in the +// list. +AST_Decl * +AST_Module::adjust_found ( + bool /*ignore_fwd*/, + bool /*full_def_only*/) +{ + return this->last_in_same_parent_scope_; +} // Involved in OBV_ namespace generation. void AST_Module::set_has_nested_valuetype (void) { UTL_Scope *parent = this->defined_in (); - - if (!this->pd_has_nested_valuetype && parent) + if (parent && !this->pd_has_nested_valuetype_) { AST_Module *pm = AST_Module::narrow_from_scope (parent); - - if (pm != 0) + if (pm) { pm->set_has_nested_valuetype (); } } - this->pd_has_nested_valuetype = 1; + this->pd_has_nested_valuetype_ = 1; } bool AST_Module::has_nested_valuetype (void) { - return this->pd_has_nested_valuetype; + return this->pd_has_nested_valuetype_; } int @@ -162,15 +186,13 @@ AST_Module::be_add_interface (AST_Interface *i, AST_Interface *ix) { // Add it to scope. - this->add_to_scope (i, - ix); + this->add_to_scope (i, ix); // Add it to set of locally referenced symbols. this->add_to_referenced (i, false, i->local_name (), ix); - return 0; } @@ -184,7 +206,6 @@ AST_Module::be_add_valuetype (AST_ValueType *v) this->add_to_referenced (v, false, v->local_name ()); - return 0; } @@ -194,7 +215,6 @@ AST_Module::referenced (AST_Decl *e, Identifier *id) { bool refd = this->UTL_Scope::referenced (e, id); - if (refd) { return true; @@ -202,67 +222,43 @@ AST_Module::referenced (AST_Decl *e, AST_Decl *d = this->look_in_prev_mods_local (e->local_name (), true); - - if (0 == d) + if (!d) { return false; } - + AST_Type *t = AST_Type::narrow_from_decl (d); - return 0 == t || t->is_defined (); + return (!t || t->is_defined ()); } -void -AST_Module::add_to_previous (AST_Module *m) +AST_Module * +AST_Module::previous_opening () { - this->prev_mods_.insert (m); + return this->previous_opening_; } 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 ()) + for (AST_Module *po = this->previous_opening_; + po; + po = po->previous_opening_) { - iter.next (m); - - for (UTL_ScopeActiveIterator i (*m, UTL_Scope::IK_decls); - !i.is_done (); - i.next ()) + for (UTL_ScopeActiveIterator iter (po, UTL_Scope::IK_decls); + !iter.is_done (); + iter.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 ())) + AST_Decl *d = iter.item (); + if ((!ignore_fwd || !d->is_fwd ()) + && !!(d = d->adjust_found (ignore_fwd, false)) + && e->case_compare (d->local_name ())) { return d; } } } - + return 0; } @@ -270,77 +266,39 @@ AST_Decl * AST_Module::look_in_prev_mods (UTL_ScopedName *e, bool full_def_only) { - 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 ()) + for (AST_Module *po = this->previous_opening_; + po; + po = po->previous_opening_) { - iter.next (m); - - for (UTL_ScopeActiveIterator i (*m, UTL_Scope::IK_decls); - !i.is_done (); - i.next ()) + for (UTL_ScopeActiveIterator iter (po, UTL_Scope::IK_decls); + !iter.is_done (); + iter.next ()) { - d = i.item (); + AST_Decl *const d = + iter.item ()->adjust_found (full_def_only, full_def_only); - if (full_def_only) + if (d && e->head ()->case_compare (d->local_name ())) { - 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) + UTL_ScopedName *sn = + static_cast<UTL_ScopedName *> (e->tail ()); + if (!sn) { - continue; + return d; // Nothing left in path, found wanted name } - } - if (e->head ()->case_compare (d->local_name ())) - { UTL_Scope *s = DeclAsScope (d); - UTL_ScopedName *sn = - static_cast<UTL_ScopedName *> (e->tail ()); - - if (sn == 0) - { - return d; - } - else if (s != 0) + if (s) { - d = s->lookup_by_name_r (sn, full_def_only); - - if (d != 0) - { - return d; - } + // Recurse down what is left of the path + return s->lookup_by_name_r (sn, full_def_only); } + + // Find next match, this one didn't work out. } } } - - return 0; -} -ACE_Unbounded_Set<AST_Module *> & -AST_Module::prev_mods (void) -{ - return this->prev_mods_; -} - -void -AST_Module::destroy (void) -{ - this->UTL_Scope::destroy (); - this->AST_Decl::destroy (); + return 0; // Not found. } int @@ -365,16 +323,7 @@ AST_Decl * AST_Module::special_lookup (UTL_ScopedName *e, bool full_def_only) { - AST_Decl *d = 0; - - if (!AST_Module::in_prev_) - { - AST_Module::in_prev_ = true; - d = this->look_in_prev_mods (e, full_def_only); - AST_Module::in_prev_ = false; - } - - return d; + return this->look_in_prev_mods (e, full_def_only); } //================================================ @@ -382,38 +331,40 @@ AST_Module::special_lookup (UTL_ScopedName *e, AST_PredefinedType * AST_Module::fe_add_predefined_type (AST_PredefinedType *t) { - return - AST_PredefinedType::narrow_from_decl ( - this->fe_add_decl (t)); + return AST_PredefinedType::narrow_from_decl ( + this->fe_add_decl (t)); } AST_Module * AST_Module::fe_add_module (AST_Module *t) { - AST_Decl *d; - AST_Module *m = 0; - - UTL_Scope *scope = t->defined_in (); - const char *prefix_holder = 0; - // If our prefix is empty, we check to see if an ancestor has one. - while (ACE_OS::strcmp (t->prefix (), "") == 0 && scope != 0) + if (!ACE_OS::strcmp (t->prefix (), "")) { - AST_Decl *parent = ScopeAsDecl (scope); - prefix_holder = parent->prefix (); - - // We have reached global scope. - if (prefix_holder == 0) + UTL_Scope *scope = t->defined_in (); + while (scope) { - break; - } + AST_Decl *parent = ScopeAsDecl (scope); + const char *prefix_holder = parent->prefix (); + if (!prefix_holder) + { + break; // We have reached global scope. + } + + t->prefix (const_cast<char *> (prefix_holder)); + if (ACE_OS::strcmp (t->prefix (), "")) + { + break; + } - t->prefix (const_cast<char *> (prefix_holder)); - scope = parent->defined_in (); + scope = parent->defined_in (); + } } // Already defined and cannot be redefined? Or already used? - if ((d = this->lookup_for_add (t)) != 0) + AST_Module *m = 0; + AST_Decl *d = this->lookup_for_add (t); + if (d) { if (!can_be_redefined (d)) { @@ -424,37 +375,61 @@ AST_Module::fe_add_module (AST_Module *t) return 0; } - m = AST_Module::narrow_from_decl (d); - // has_ancestor() returns TRUE if both nodes are the same. - if (t != m) + m = AST_Module::narrow_from_decl (d); + if (t != m && t->has_ancestor (d)) { - if (t->has_ancestor (d)) - { - idl_global->err ()->redefinition_in_scope (t, - d); - return 0; - } + idl_global->err ()->redefinition_in_scope (t, d); + return 0; } const char *prev_prefix = d->prefix (); const char *this_prefix = t->prefix (); - if (ACE_OS::strcmp (this_prefix, "") == 0) + if (!ACE_OS::strcmp (this_prefix, "")) { t->prefix (const_cast<char *> (prev_prefix)); } - else + else if (!ACE_OS::strcmp (prev_prefix, "")) { - if (ACE_OS::strcmp (prev_prefix, "") == 0) + d->prefix (const_cast<char *> (this_prefix)); + } + } + + // Now we are actually adding this new module to the active + // scopes, ensure that the previous openings are all updated + // so that this new module is recorded as the current + // "last module" definition in our scope. + AST_Module *first_opening = t->previous_opening_; + if (first_opening) + { + // When we created the module we simply stored the first + // previous module we found (if any), we actually want + // to refer to that module's LAST opening in that same scope + // except this module itself (which isn't yet recorded anyway). + t->previous_opening_ = first_opening->last_in_same_parent_scope_; + if (first_opening->defined_in () == this) + { + // Since the previous openings are in our own scope, + // make sure that these all point to this new module. + for (AST_Module *pm = t->previous_opening_; + pm; + pm = pm->previous_opening_) { - d->prefix (const_cast<char *> (this_prefix)); + pm->last_in_same_parent_scope_ = t; + if (pm == first_opening) + { + // Even if there are still more previous modules, + // the ones before this one are in a different + // scope and do not need to be updated. + break; + } } } } // If this node is not a reopened module, add it to scope and referenced. - if (m == 0 || t != m) + if (!m || t != m) { // Add it to scope. this->add_to_scope (t); @@ -643,6 +618,3 @@ AST_Module::fe_add_porttype (AST_PortType *t) AST_PortType::narrow_from_decl ( this->fe_add_decl (t)); } - -IMPL_NARROW_FROM_DECL(AST_Module) -IMPL_NARROW_FROM_SCOPE(AST_Module) diff --git a/TAO/TAO_IDL/ast/ast_structure_fwd.cpp b/TAO/TAO_IDL/ast/ast_structure_fwd.cpp index cecc93901e6..724ba6ada86 100644 --- a/TAO/TAO_IDL/ast/ast_structure_fwd.cpp +++ b/TAO/TAO_IDL/ast/ast_structure_fwd.cpp @@ -89,4 +89,27 @@ AST_StructureFwd::destroy (void) this->AST_Type::destroy (); } +bool +AST_StructureFwd::is_fwd (void) +{ + return true; // This is a fwd declared type +} + +// We don't actually want the forward declaration, +// but want to return the full definition member, +// whether defined yet or not. +AST_Decl * +AST_StructureFwd::adjust_found ( + bool ignore_fwd, + bool full_def_only) +{ + if (ignore_fwd) + { + AST_Structure *s = this->full_definition (); + return (full_def_only && !s->is_defined () ? 0 : s); + } + + return this; +} + IMPL_NARROW_FROM_DECL (AST_StructureFwd) diff --git a/TAO/TAO_IDL/ast/ast_template_module_ref.cpp b/TAO/TAO_IDL/ast/ast_template_module_ref.cpp index 645a9433442..56b5f0a7d2b 100644 --- a/TAO/TAO_IDL/ast/ast_template_module_ref.cpp +++ b/TAO/TAO_IDL/ast/ast_template_module_ref.cpp @@ -63,5 +63,19 @@ AST_Template_Module_Ref::ast_accept (ast_visitor *visitor) return visitor->visit_template_module_ref (this); } +// If IDL module has been created in a scope corresponding +// to this node. That's the one we want to match, NOT this +// AST_Template_Module_Ref, and it occurs in the scope right +// after this node, so we'll match what we're looking for on +// the next iteration of the search. So for this immediate +// adjustment we return no match. +AST_Decl * +AST_Template_Module_Ref::adjust_found ( + bool ignore_fwd, + bool /*full_def_only*/) +{ + return ignore_fwd ? 0 : this; +} + IMPL_NARROW_FROM_DECL (AST_Template_Module_Ref) diff --git a/TAO/TAO_IDL/be/be_generator.cpp b/TAO/TAO_IDL/be/be_generator.cpp index baaa9a32f1f..312aa23fd9c 100644 --- a/TAO/TAO_IDL/be/be_generator.cpp +++ b/TAO/TAO_IDL/be/be_generator.cpp @@ -1,5 +1,4 @@ // $Id$ - /* COPYRIGHT @@ -147,15 +146,7 @@ AST_Module * be_generator::create_module (UTL_Scope *s, UTL_ScopedName *n) { - // 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; - ACE_NEW_RETURN (retval, - 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); @@ -164,56 +155,46 @@ be_generator::create_module (UTL_Scope *s, { // 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 ()); + AST_Module *m = AST_Module::narrow_from_decl (iter.item ()); - if (m != 0) + if (m && m->local_name ()->compare (n->last_component ())) { - // Does it have the same name as the one we're - // supposed to create. - if (m->local_name ()->compare (n->last_component ())) - { - // 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 ())); - } + // Create this new module with referance to the + // "first" previous module found in scope. + ACE_NEW_RETURN (retval, be_module (n, m), 0); + retval->prefix (const_cast<char *> (m->prefix ())); + return retval; } } - // If this scope is itself a module, and has been previously - // opened, the previous opening may contain a previous opening + // Since the scope didn't contain the same module name, it + // doesn't mean that we haven't see it before. If the scope + // is itself a module, and has been previously opened, any + // of the previous openings may contain a previous opening // of the module we're creating. - m = AST_Module::narrow_from_scope (s); - - if (m != 0) + AST_Module *prev_module = AST_Module::narrow_from_scope (s); + if (prev_module) { - for (ACE_Unbounded_Set<AST_Module *>::CONST_ITERATOR i ( - m->prev_mods ()); - !i.done (); - i.advance ()) + while (!!(prev_module = prev_module->previous_opening ())) { - AST_Module **mm = 0; - i.next (mm); - - for (UTL_ScopeActiveIterator si (*mm, UTL_Scope::IK_decls); - !si.is_done (); - si.next ()) + for (UTL_ScopeActiveIterator iter (prev_module, UTL_Scope::IK_decls); + !iter.is_done (); + iter.next ()) { - AST_Decl *d = si.item (); - - if (retval->local_name ()->case_compare (d->local_name ())) + AST_Module *m = AST_Module::narrow_from_decl (iter.item ()); + if (m && m->local_name ()->compare (n->last_component ())) { - m = AST_Module::narrow_from_decl (d); - - if (m != 0) - { - retval->add_to_previous (m); - } + // Create this new module with referance to the + // "first" previous module found in scope. + ACE_NEW_RETURN (retval, be_module (n, m), 0); + return retval; } } } } + // There is no previous module to be found + ACE_NEW_RETURN (retval, be_module (n), 0); return retval; } @@ -236,7 +217,7 @@ be_generator::create_interface (UTL_ScopedName *n, l, a), 0); - + /// Trigger this interation over the included pragmas when the /// first local interface is seen in the main file. In an /// executor IDL file (the case we want), this happens near the diff --git a/TAO/TAO_IDL/be/be_module.cpp b/TAO/TAO_IDL/be/be_module.cpp index 12830451390..4e58cf830bd 100644 --- a/TAO/TAO_IDL/be/be_module.cpp +++ b/TAO/TAO_IDL/be/be_module.cpp @@ -1,4 +1,3 @@ - //============================================================================= /** * @file be_module.cpp @@ -8,7 +7,6 @@ * Extension of class AST_Module that provides additional means for C++ * mapping of a module * - * * @author Copyright 1994-1995 by Sun Microsystems * @author Inc. and Aniruddha Gokhale */ @@ -17,15 +15,13 @@ #include "be_module.h" #include "be_visitor.h" -be_module::be_module (UTL_ScopedName *n) +be_module::be_module (UTL_ScopedName *n, AST_Module *previous) : COMMON_Base (), - AST_Decl (AST_Decl::NT_module, - n), + AST_Decl (AST_Decl::NT_module, n), UTL_Scope (AST_Decl::NT_module), - AST_Module (n), + AST_Module (n, previous), be_scope (AST_Decl::NT_module), - be_decl (AST_Decl::NT_module, - n) + be_decl (AST_Decl::NT_module, n) { } diff --git a/TAO/TAO_IDL/be_include/be_module.h b/TAO/TAO_IDL/be_include/be_module.h index af0cc580666..3d53e4ff0c9 100644 --- a/TAO/TAO_IDL/be_include/be_module.h +++ b/TAO/TAO_IDL/be_include/be_module.h @@ -27,7 +27,7 @@ class be_module : public virtual AST_Module, public virtual be_decl { public: - be_module (UTL_ScopedName *n); + be_module (UTL_ScopedName *n, AST_Module *previous = 0); /// Cleanup method. virtual void destroy (void); diff --git a/TAO/TAO_IDL/include/ast_component_fwd.h b/TAO/TAO_IDL/include/ast_component_fwd.h index 7b2f355925a..7031b09c92a 100644 --- a/TAO/TAO_IDL/include/ast_component_fwd.h +++ b/TAO/TAO_IDL/include/ast_component_fwd.h @@ -29,6 +29,9 @@ public: // Visiting. virtual int ast_accept (ast_visitor *visitor); + // Is this decl a forward declared type (Yes) + virtual bool is_fwd (void); + static AST_Decl::NodeType const NT; }; diff --git a/TAO/TAO_IDL/include/ast_decl.h b/TAO/TAO_IDL/include/ast_decl.h index b8434de1ea7..8330d142146 100644 --- a/TAO/TAO_IDL/include/ast_decl.h +++ b/TAO/TAO_IDL/include/ast_decl.h @@ -94,11 +94,15 @@ class ast_visitor; class TAO_IDL_FE_Export COMMON_Base { -public: +protected: COMMON_Base (bool local = false, bool abstract = false); - virtual ~COMMON_Base (void) {} + virtual ~COMMON_Base (void); + +public: + // A no-op, overridden in the child classes. + virtual void destroy (void); // Accessor needs to get overridden for a few types. virtual bool is_local (void); @@ -107,9 +111,6 @@ public: bool is_abstract (void) const; void is_abstract (bool val); - // A no-op, overridden in the child classes. - virtual void destroy (void); - protected: bool is_local_; bool is_abstract_; @@ -176,6 +177,17 @@ public: virtual ~AST_Decl (void); + // Cleanup method. + virtual void destroy (void); + + // If this decl has been found, some types need to be + // moved onto their true definitions etc. Defaults to + // NO adjustment. + virtual AST_Decl *adjust_found (bool ignore_fwd, bool full_def_only); + + // Is this decl a forward declared type (default false) + virtual bool is_fwd (void); + // Data Accessors. bool imported (void); @@ -265,9 +277,6 @@ public: // Visiting. virtual int ast_accept (ast_visitor *visitor); - // Cleanup method. - virtual void destroy (void); - // Other operations // Return TRUE if "this" has "s" as an ancestor. diff --git a/TAO/TAO_IDL/include/ast_interface_fwd.h b/TAO/TAO_IDL/include/ast_interface_fwd.h index 20894a3c58e..91e9591d7dc 100644 --- a/TAO/TAO_IDL/include/ast_interface_fwd.h +++ b/TAO/TAO_IDL/include/ast_interface_fwd.h @@ -105,6 +105,14 @@ public: // Visiting. virtual int ast_accept (ast_visitor *visitor); + // Is this decl a forward declared type (Yes) + virtual bool is_fwd (void); + + // We don't actually want the forward declaration, + // but want to return the full definition member, + // whether defined yet or not. + virtual AST_Decl *adjust_found (bool ignore_fwd, bool full_def_only); + static AST_Decl::NodeType const NT; private: diff --git a/TAO/TAO_IDL/include/ast_module.h b/TAO/TAO_IDL/include/ast_module.h index d3ab51382ac..91c6b48ea5a 100644 --- a/TAO/TAO_IDL/include/ast_module.h +++ b/TAO/TAO_IDL/include/ast_module.h @@ -81,10 +81,17 @@ class TAO_IDL_FE_Export AST_Module : public virtual AST_Decl, public virtual UTL_Scope { public: - AST_Module (UTL_ScopedName *n); + static AST_Decl::NodeType const NT; + + // Constructor. + AST_Module (UTL_ScopedName *n, AST_Module *prev = 0); + // Destructor. virtual ~AST_Module (void); + // Cleanup function. + virtual void destroy (void); + // Narrowing. DEF_NARROW_FROM_DECL(AST_Module); DEF_NARROW_FROM_SCOPE(AST_Module); @@ -110,10 +117,8 @@ public: virtual bool referenced (AST_Decl *e, Identifier *id = 0); - // Add decls from previous opening of this module to the - // 'previous' set of this module, along with the argument's - // own 'previous' set. - void add_to_previous (AST_Module *m); + // Accessor to this module's previous opening. + AST_Module *previous_opening (); // Called to look up some declaration // in a previous opening of this module. @@ -125,12 +130,6 @@ public: 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); - - // Cleanup function. - virtual void destroy (void); - // Visiting. virtual int ast_accept (ast_visitor *visitor); @@ -142,7 +141,10 @@ public: virtual AST_Decl *special_lookup (UTL_ScopedName *e, bool full_def_only); - static AST_Decl::NodeType const NT; + // We actually want to match the LAST module found in + // the scope being searched not the FIRST one in the + // list. + virtual AST_Decl *adjust_found (bool ignore_fwd, bool full_def_only); // Scope Management Protocol @@ -221,19 +223,18 @@ public: virtual AST_PortType *fe_add_porttype (AST_PortType *pt); - -private: - bool pd_has_nested_valuetype; - ACE_Unbounded_Set<AST_Module *> prev_mods_; - /// Container for previous openings of this module. +private: // Data + bool pd_has_nested_valuetype_; + + AST_Module *previous_opening_; + /// The immediatly previous opening of this module. + + AST_Module *last_in_same_parent_scope_; + /// Pointer to the last opening of this module in the same parent AST_Template_Module_Inst *from_inst_; /// Reference to the instantiation that created us, if any. - - static bool in_prev_; - /// Flag to prevent exponential repeats of search through - /// previous openings. }; #endif // _AST_MODULE_AST_MODULE_HH diff --git a/TAO/TAO_IDL/include/ast_structure_fwd.h b/TAO/TAO_IDL/include/ast_structure_fwd.h index 8fb3dbf6e64..6315e24ce2e 100644 --- a/TAO/TAO_IDL/include/ast_structure_fwd.h +++ b/TAO/TAO_IDL/include/ast_structure_fwd.h @@ -36,6 +36,14 @@ public: // Visiting. virtual int ast_accept (ast_visitor *visitor); + // Is this decl a forward declared type (Yes) + virtual bool is_fwd (void); + + // We don't actually want the forward declaration, + // but want to return the full definition member, + // whether defined yet or not. + virtual AST_Decl *adjust_found (bool ignore_fwd, bool full_def_only); + static AST_Decl::NodeType const NT; private: diff --git a/TAO/TAO_IDL/include/ast_template_module_ref.h b/TAO/TAO_IDL/include/ast_template_module_ref.h index f592554ab39..d00cd3509b6 100644 --- a/TAO/TAO_IDL/include/ast_template_module_ref.h +++ b/TAO/TAO_IDL/include/ast_template_module_ref.h @@ -35,6 +35,14 @@ public: // Visiting. virtual int ast_accept (ast_visitor *visitor); + // If IDL module has been created in a scope corresponding + // to this node. That's the one we want to match, NOT this + // AST_Template_Module_Ref, and it occurs in the scope right + // after this node, so we'll match what we're looking for on + // the next iteration of the search. So for this immediate + // adjustment we return no match. + virtual AST_Decl *adjust_found (bool ignore_fwd, bool full_def_only); + static AST_Decl::NodeType const NT; private: diff --git a/TAO/TAO_IDL/include/utl_scope.h b/TAO/TAO_IDL/include/utl_scope.h index 6fa5da565f0..5756f966643 100644 --- a/TAO/TAO_IDL/include/utl_scope.h +++ b/TAO/TAO_IDL/include/utl_scope.h @@ -508,8 +508,6 @@ 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_scope.cpp b/TAO/TAO_IDL/util/utl_scope.cpp index 7869415dc57..7718f187ee1 100644 --- a/TAO/TAO_IDL/util/utl_scope.cpp +++ b/TAO/TAO_IDL/util/utl_scope.cpp @@ -281,49 +281,49 @@ UTL_Scope::redef_clash (AST_Decl::NodeType new_nt, AST_Decl::NodeType scope_elem_nt) { switch (new_nt) - { - case AST_Decl::NT_module: - return scope_elem_nt != AST_Decl::NT_module; + { + case AST_Decl::NT_module: + return scope_elem_nt != AST_Decl::NT_module; - case AST_Decl::NT_struct: - case AST_Decl::NT_struct_fwd: - return scope_elem_nt != AST_Decl::NT_struct_fwd; + case AST_Decl::NT_struct: + case AST_Decl::NT_struct_fwd: + return scope_elem_nt != AST_Decl::NT_struct_fwd; - case AST_Decl::NT_union: - case AST_Decl::NT_union_fwd: - return scope_elem_nt != AST_Decl::NT_union_fwd; + case AST_Decl::NT_union: + case AST_Decl::NT_union_fwd: + return scope_elem_nt != AST_Decl::NT_union_fwd; - case AST_Decl::NT_interface: - return scope_elem_nt != AST_Decl::NT_interface_fwd; + case AST_Decl::NT_interface: + return scope_elem_nt != AST_Decl::NT_interface_fwd; - case AST_Decl::NT_component: - return scope_elem_nt != AST_Decl::NT_component_fwd; + case AST_Decl::NT_component: + return scope_elem_nt != AST_Decl::NT_component_fwd; - case AST_Decl::NT_interface_fwd: - return ( scope_elem_nt != AST_Decl::NT_interface_fwd - && scope_elem_nt != AST_Decl::NT_interface); + case AST_Decl::NT_interface_fwd: + return ( scope_elem_nt != AST_Decl::NT_interface_fwd + && scope_elem_nt != AST_Decl::NT_interface); - case AST_Decl::NT_component_fwd: - return ( scope_elem_nt != AST_Decl::NT_component_fwd - && scope_elem_nt != AST_Decl::NT_component); + case AST_Decl::NT_component_fwd: + return ( scope_elem_nt != AST_Decl::NT_component_fwd + && scope_elem_nt != AST_Decl::NT_component); - case AST_Decl::NT_valuetype: - return scope_elem_nt != AST_Decl::NT_valuetype_fwd; + case AST_Decl::NT_valuetype: + return scope_elem_nt != AST_Decl::NT_valuetype_fwd; - case AST_Decl::NT_eventtype: - return scope_elem_nt != AST_Decl::NT_eventtype_fwd; + case AST_Decl::NT_eventtype: + return scope_elem_nt != AST_Decl::NT_eventtype_fwd; - case AST_Decl::NT_valuetype_fwd: - return ( scope_elem_nt != AST_Decl::NT_valuetype_fwd - && scope_elem_nt != AST_Decl::NT_valuetype); + case AST_Decl::NT_valuetype_fwd: + return ( scope_elem_nt != AST_Decl::NT_valuetype_fwd + && scope_elem_nt != AST_Decl::NT_valuetype); - case AST_Decl::NT_eventtype_fwd: - return ( scope_elem_nt != AST_Decl::NT_eventtype_fwd - && scope_elem_nt != AST_Decl::NT_eventtype); + case AST_Decl::NT_eventtype_fwd: + return ( scope_elem_nt != AST_Decl::NT_eventtype_fwd + && scope_elem_nt != AST_Decl::NT_eventtype); - default: - return true; - } + default: + return true; + } } void @@ -487,9 +487,9 @@ UTL_Scope::fe_add_decl (AST_Decl *t) AST_Decl::NodeType tnt = t->node_type (); AST_Decl::NodeType dnt = d->node_type (); - /// Factories are not inherited, so they can be - /// redefined, but not in the same scope (home or - /// valuetype). + // Factories are not inherited, so they can be + // redefined, but not in the same scope (home or + // valuetype). bool inherited_factory = ( tnt == AST_Decl::NT_factory && dnt == AST_Decl::NT_factory @@ -505,12 +505,12 @@ UTL_Scope::fe_add_decl (AST_Decl *t) } } - /// For convenience, AST_Template_Module_Inst inherits - /// from AST_Field, but has a node type of NT_module. - /// Since we then can't add it using fe_add_module(), a - /// check is needed here to avoid a redefinition error, - /// if the instantiated module is meant to reopen a - /// previous one. + // For convenience, AST_Template_Module_Inst inherits + // from AST_Field, but has a node type of NT_module. + // Since we then can't add it using fe_add_module(), a + // check is needed here to avoid a redefinition error, + // if the instantiated module is meant to reopen a + // previous one. AST_Decl::NodeType lnt = d->node_type (); AST_Decl::NodeType ant = t->node_type (); @@ -574,8 +574,8 @@ UTL_Scope::fe_add_ref_decl (AST_Field *t) } } - /// Catches struct/union/exception which all maintain a queue - /// for fields as distinct from decls and enum values. + // Catches struct/union/exception which all maintain a queue + // for fields as distinct from decls and enum values. AST_Structure *s = AST_Structure::narrow_from_scope (this); if (s) { @@ -611,8 +611,8 @@ UTL_Scope::fe_add_full_struct_type (AST_Structure *t) AST_Decl::NodeType nt = ScopeAsDecl (this)->node_type (); - /// Decls inside a struct or union are also referenced by - /// fields, and so must be handled differently. + // Decls inside a struct or union are also referenced by + // fields, and so must be handled differently. if ( nt == AST_Decl::NT_struct || nt == AST_Decl::NT_union || nt == AST_Decl::NT_except) @@ -638,18 +638,15 @@ UTL_Scope::fe_add_fwd_struct_type (AST_StructureFwd *t) AST_Decl *d = this->lookup_for_add (t); if (d) { - AST_Decl::NodeType nt = d->node_type (); - // There used to be another check here ANDed with the one below: // d->defined_in () == this. But lookup_for_add() calls only // lookup_by_name_local(), which does not bump up the scope, // and look_in_prev_mods() for modules. If look_in_prev_mods() // finds something, the scopes will NOT be the same pointer // value, but the result is what we want. - if (nt == AST_Decl::NT_struct) + if (d->node_type () == AST_Decl::NT_struct) { - AST_Structure *s = AST_Structure::narrow_from_decl (d); - t->set_full_definition (s); + t->set_full_definition (AST_Structure::narrow_from_decl (d)); } else if (!can_be_redefined (d)) { @@ -1003,8 +1000,7 @@ UTL_Scope::lookup_pseudo (Identifier *e) i.next ()) { AST_Decl *d = i.item (); - Identifier *item_name = d->local_name (); - if (e->case_compare (item_name)) + if (e->case_compare (d->local_name ())) { // These have to be located here because we are just looking // up a scoped name - skip for imported nodes. @@ -1216,175 +1212,138 @@ UTL_Scope::lookup_by_name_local (Identifier *e, !i.is_done (); i.next ()) { - AST_Decl *tmp = i.item (); - Identifier *item_name = tmp->local_name (); - - if (item_name - // 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. - && (in_corba || ACE_OS::strcmp (tmp->name ()->head ()->get_string (), "CORBA")) - && e->case_compare (item_name)) + d = i.item ()->adjust_found (true, full_def_only); + if (d) { - if (AST_Template_Module_Ref::narrow_from_decl (tmp)) + Identifier *item_name = d->local_name (); + if (item_name + // 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. + && (in_corba || ACE_OS::strcmp ( + d->name ()->head ()->get_string (), "CORBA")) + && e->case_compare (item_name)) { - // An IDL module has been created in this scope corresponding - // to this node. That's the one we want to match, and it - // occurs in the scope right after this node, so we'll match - // what we're looking for on the next iteration. - continue; + return d; // We have found the one and only one we are looking for. } - - d = tmp; - AST_Decl::NodeType nt = tmp->node_type (); - if (nt == AST_Decl::NT_module) - { - // We are wanting the LAST module opening in this scope, so having - // stored this one, keep searching in case we find another later on. - continue; - } - - // 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_struct_fwd - || nt == AST_Decl::NT_union_fwd) - { - d = AST_StructureFwd::narrow_from_decl (tmp)->full_definition (); - } - else 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) - { - d = AST_InterfaceFwd::narrow_from_decl (tmp)->full_definition (); - } - - break; // We have found the one and only one we are looking for. } } - if (!d) + // Ok the name wasn't found in the current scope, if this + // scope is a module, we can check it's previous openings! + AST_Module *m = AST_Module::narrow_from_scope (this); + if (m) { - AST_Module *m = AST_Module::narrow_from_scope (this); - if (m) + d = m->look_in_prev_mods_local (e); + if (d && (!full_def_only || d->is_defined ())) { - d = m->look_in_prev_mods_local (e); - if (d && full_def_only && !d->is_defined ()) - { - d = 0; - } + return d; } - else + } + else + { + // Or if this scope is an interface, we can check if + // it was inherited! + AST_Interface *i = AST_Interface::narrow_from_scope (this); + if (i) { - AST_Interface *i = - AST_Interface::narrow_from_scope (this); - if (i) + d = i->look_in_inherited_local (e); + if (d) { - d = i->look_in_inherited_local (e); + return d; } } } - /// There are some cases where the iteration over IK_decls - /// above will fail because what we're searching for has been - /// added only to the local types. It's less complicated to - /// do the iteration below only as a last resort. - if (!d) + // There are some cases where the iteration over IK_decls + // above will fail because what we're searching for has been + // added only to the local types. It's less complicated to + // do the iteration below only as a last resort. + for (UTL_ScopeActiveIterator i (this, IK_localtypes); + !i.is_done (); + i.next ()) { - for (UTL_ScopeActiveIterator i (this, IK_localtypes); - !i.is_done (); - i.next ()) + d = i.item (); + if (e->case_compare (d->local_name ())) { - AST_Decl *l = i.item (); - if (e->case_compare (l->local_name ())) - { - d = l; - break; - } + return d; } } - return d; + return 0; } AST_Decl * UTL_Scope::lookup_by_name (UTL_ScopedName *e, bool full_def_only) { - /// Empty name? Exit immediately. + // Empty name? Exit immediately. if (!e) { return 0; } - UTL_ScopedName *work_name = e; - UTL_Scope *work_scope = this; + UTL_Scope *work = this; + Identifier *const name = e->head (); - /// If name starts with "::" or "" start lookup in global scope, - /// if we're not there already, short_circuiting the - /// scope-expanding iteration below. - const bool global_scope_name = this->is_global_name (e->head ()); + // If name starts with "::" or "" start lookup in global scope, + // if we're not there already, short_circuiting the + // scope-expanding iteration below. + const bool global_scope_name = work->is_global_name (name); if (global_scope_name) { - work_name = static_cast<UTL_ScopedName *> (e->tail ()); - work_scope = idl_global->root (); + e = static_cast<UTL_ScopedName *> (e->tail ()); + work = idl_global->root (); } - AST_Decl *d = - work_scope->lookup_by_name_r (work_name, full_def_only); - - UTL_Scope *outer = ScopeAsDecl (work_scope)->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. - while (!d && outer) + AST_Decl *d = work->lookup_by_name_r (e, full_def_only); + if (!d) { - d = outer->lookup_by_name_r (work_name, full_def_only); - - AST_Decl *s = ScopeAsDecl (outer); - outer = s->defined_in (); + // If all else fails, look though each outer scope. + for (UTL_Scope *outer = ScopeAsDecl (work)->defined_in (); + outer; + outer = ScopeAsDecl (outer)->defined_in ()) + { + d = outer->lookup_by_name_r (e, full_def_only); + if (d) + { + break; // Ok found it, stop searching. + } + } } - if (!global_scope_name && d) + ACE_Unbounded_Queue<AST_Decl *> &masks = idl_global->masking_scopes (); + if (d && !global_scope_name) { - ACE_CDR::ULong slot = 0uL; - AST_Decl *outer_scope = 0; - const char *head = e->head ()->get_string (); - for (ACE_Unbounded_Queue<AST_Decl *>::CONST_ITERATOR i (masks); - !i.done (); - i.advance (), ++slot) + ACE_Unbounded_Queue<AST_Decl *>::CONST_ITERATOR i (masks); + AST_Decl **item = 0; + if (i.next (item)) { - AST_Decl **item = 0; - i.next (item); + // The first queue item (last enqueued) will always + // match "name", but does not indicate an error. + AST_Decl *outer_decl = *item; - /// The first queue item (last enqueued) will always - /// match e->head(), but does not indicate an error. - if (!slot) + // Now check that the rest of the names don't collide + const char *const name_str = name->get_string (); + while (i.advance ()) { - outer_scope = *item; - continue; - } - - const char *lname = (*item)->local_name ()->get_string (); - if (!ACE_OS::strcmp (lname, head) - && !(*item)->masking_checks (outer_scope)) - { - idl_global->err ()->scope_masking_error (d, *item); - d = 0; - break; + i.next (item); + const char *const item_name_str = + (*item)->local_name ()->get_string (); + if (!ACE_OS::strcmp (item_name_str, name_str) + && !(*item)->masking_checks (outer_decl)) + { + idl_global->err ()->scope_masking_error (d, *item); + d = 0; // Hidden scopes can't be used indirectly. + break; + } } } } masks.reset (); - this->add_to_referenced (d, false, e->head ()); + this->add_to_referenced (d, false, name); return d; } @@ -1392,105 +1351,101 @@ AST_Decl * UTL_Scope::lookup_by_name_r (UTL_ScopedName *e, bool full_def_only) { - // 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. - AST_Decl *d = this->lookup_pseudo (e->head ()); - if (d) + bool work_another_level; + UTL_Scope *work = this; + do { - return d; - } - - if (this->idl_keyword_clash (e->head ())) - { - 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 = - 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) + // 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. + AST_Decl *d = work->lookup_pseudo (e->head ()); + if (d) { - return param_holder; + return d; } - } - bool in_corba = !ACE_OS::strcmp (e->head ()->get_string (), "CORBA"); - for (UTL_ScopeActiveIterator i (this, IK_decls); - !i.is_done (); - i.next ()) - { - AST_Decl *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")) + if (work->idl_keyword_clash (e->head ())) { - continue; + return 0; } - if (tmp->local_name ()->case_compare (e->head ())) + // 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) { - d = tmp; - if (e->length () == 1) + // 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. + AST_Param_Holder *param_holder = UTL_Scope::match_param (e); + if (param_holder) { - d = this->local_checks (d, full_def_only); + return param_holder; } - else + } + + work_another_level = false; // Until we find something. + bool in_corba = !ACE_OS::strcmp (e->head ()->get_string (), "CORBA"); + for (UTL_ScopeActiveIterator i (work, IK_decls); + !i.is_done (); + i.next ()) + { + d = i.item ()->adjust_found (true, full_def_only); + if (d + // 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. + && (in_corba || + ACE_OS::strcmp (d->name ()->head ()->get_string (), "CORBA")) + && d->local_name ()->case_compare (e->head ())) { - UTL_Scope *s = DeclAsScope (d); - if (s) + // Ok we found a match, is there any more to find? + if (e->length () == 1) { - idl_global->masking_scopes ().enqueue_head (d); + return d; // Last scope name matched + } - UTL_ScopedName *sn = - static_cast<UTL_ScopedName *> (e->tail ()); - d = s->lookup_by_name_r (sn, full_def_only); + UTL_Scope *next = DeclAsScope (d); // The next scope to search + if (next) + { + work = next; + work_another_level = true; + idl_global->masking_scopes ().enqueue_head (d); + e = static_cast<UTL_ScopedName *> (e->tail ()); + break; } + + // Template weirdness, actual one we want should be + // found next in this search, keep going. } } - } + } while (work_another_level); - /// 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. - if (!d) + // 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. + if (e->length () == 1) { - for (UTL_ScopeActiveIterator i (this, IK_localtypes); + for (UTL_ScopeActiveIterator i (work, IK_localtypes); !i.is_done (); i.next ()) { - AST_Decl *tmp = i.item (); - if (tmp->local_name ()->case_compare (e->head ())) + AST_Decl *d = i.item (); + if (d->local_name ()->case_compare (e->head ())) { - d = tmp; - break; + return d; } } } - if (!d) - { - d = this->special_lookup (e, full_def_only); - } - - return d; + // Last resort, check other module openings of working scope. + return work->special_lookup (e, full_def_only); } // Add a node to set of nodes referenced in this scope. @@ -1500,6 +1455,7 @@ UTL_Scope::add_to_referenced (AST_Decl *e, Identifier *id, AST_Decl *ex) { + // Empty name? Exit immediately. if (!e) { return; @@ -1541,7 +1497,7 @@ UTL_Scope::add_to_referenced (AST_Decl *e, for (long i = 0; i < oreferenced_allocated; ++i) { - tmp[i] = this->pd_referenced[i]; + tmp [i] = this->pd_referenced [i]; } delete [] this->pd_referenced; @@ -1555,21 +1511,15 @@ UTL_Scope::add_to_referenced (AST_Decl *e, } else if (this->referenced (ex)) { - for (long i = this->pd_referenced_used; 0 < i; --i) + long i; + for (i = this->pd_referenced_used; + 0 < i && this->pd_referenced [i - 1] != ex; + --i) { - this->pd_referenced[i] = this->pd_referenced[i - 1]; - - if (this->pd_referenced[i - 1] == ex) - { - this->pd_referenced[i] = e; - break; - } - } - - if (0 < this->pd_referenced_used) - { - ++this->pd_referenced_used; + this->pd_referenced [i] = this->pd_referenced [i - 1]; } + this->pd_referenced [i] = e; + ++this->pd_referenced_used; } // Now, if recursive is specified and "this" is not a common ancestor @@ -1609,7 +1559,6 @@ UTL_Scope::add_to_name_referenced (Identifier *id) } delete [] this->pd_name_referenced; - this->pd_name_referenced = name_tmp; } @@ -1629,7 +1578,6 @@ UTL_Scope::replace_referenced (AST_Decl *old_decl, break; } } - } void @@ -1658,14 +1606,15 @@ UTL_Scope::add_to_scope (AST_Decl *e, Identifier *decl_name = e->local_name (); char *decl_string = decl_name->get_string (); + AST_Decl::NodeType new_nt = e->node_type (); // First, make sure there's no clash between e, that was // just declared, and some other identifier referenced // in this scope. AST_Decl **tmp = this->pd_decls; for (long i = this->pd_decls_used; - 0 < i; - --i, ++tmp) + i--; // NOTE i-- test + ++tmp) { // A local declaration doesn't use a scoped name. Identifier *ref_name = (*tmp)->local_name (); @@ -1675,11 +1624,10 @@ UTL_Scope::add_to_scope (AST_Decl *e, // error, unless they're both modules (which can be // reopened) or we have a belated definition of a // forward-declared interface. - AST_Decl::NodeType new_nt = e->node_type (); AST_Decl::NodeType scope_elem_nt = (*tmp)->node_type (); - if (decl_name->compare (ref_name) - && this->redef_clash (new_nt, scope_elem_nt)) + if (this->redef_clash (new_nt, scope_elem_nt) + && decl_name->compare (ref_name)) { idl_global->err ()->redef_error (decl_string, ref_string); @@ -1689,8 +1637,8 @@ UTL_Scope::add_to_scope (AST_Decl *e, } // If the spellings differ only by case, it's also an error, // unless one, but not both of the identifiers were escaped. - else if (decl_name->case_compare_quiet (ref_name) - && !(decl_name->escaped () ^ ref_name->escaped ())) + else if (!(decl_name->escaped () ^ ref_name->escaped ()) + && decl_name->case_compare_quiet (ref_name)) { if (idl_global->case_diff_error ()) { @@ -1708,12 +1656,11 @@ UTL_Scope::add_to_scope (AST_Decl *e, } } - AST_Decl *d = ScopeAsDecl (this); - AST_Decl::NodeType nt = d->node_type (); - // The name of any scope except the unnamed scope formed by an operation // may not be redefined immediately within (and the root scope has no name). // As well as OBV factory construct. + AST_Decl *d = ScopeAsDecl (this); + AST_Decl::NodeType nt = d->node_type (); if ( nt != AST_Decl::NT_root && nt != AST_Decl::NT_op && nt != AST_Decl::NT_factory) @@ -1760,11 +1707,10 @@ UTL_Scope::add_to_scope (AST_Decl *e, ACE_NEW (tmp, AST_Decl *[pd_decls_allocated]); for (long i = 0; i < odecls_allocated; ++i) { - tmp[i] = this->pd_decls[i]; + tmp [i] = this->pd_decls [i]; } delete [] this->pd_decls; - this->pd_decls = tmp; } @@ -1775,17 +1721,14 @@ UTL_Scope::add_to_scope (AST_Decl *e, } else { - for (long i = this->pd_decls_used; 0 < i; --i) + long i; + for (i = this->pd_decls_used; + 0 < i && this->pd_decls [i - 1] != ex; + --i) { - this->pd_decls[i] = this->pd_decls[i - 1]; - - if (this->pd_decls[i - 1] == ex) - { - this->pd_decls[i] = e; - break; - } + this->pd_decls [i] = this->pd_decls [i - 1]; } - + this->pd_decls [i] = e; ++this->pd_decls_used; } } @@ -1826,10 +1769,13 @@ bool UTL_Scope::referenced (AST_Decl *e, Identifier *id) { + Identifier *test = e->local_name (); + AST_Decl::NodeType nt = e->node_type (); + AST_Decl **tmp = this->pd_referenced; for (long i = this->pd_referenced_used; - 0 < i; - --i, ++tmp) + i--; // NOTE test with i-- + ++tmp) { // Same node? if (*tmp == e) @@ -1839,14 +1785,10 @@ UTL_Scope::referenced (AST_Decl *e, // Are we definging a forward declared struct, union, or interface, // or reopening a module? - if (!this->redef_clash (e->node_type (), (*tmp)->node_type ())) + if (!this->redef_clash (nt, (*tmp)->node_type ()) + && (*tmp)->local_name ()->compare (test)) { - Identifier *member = (*tmp)->local_name (); - Identifier *test = e->local_name (); - if (member->compare (test)) - { - return false; - } + return false; } } @@ -1860,8 +1802,8 @@ UTL_Scope::referenced (AST_Decl *e, { Identifier **name_tmp = this->pd_name_referenced; for (long j = this->pd_name_referenced_used; - 0 < j; - --j, ++name_tmp) + j--; // NOTE test with j-- + ++name_tmp) { // If we are a module, there is no clash, if we // are an interface, this is not the right place to @@ -1870,18 +1812,18 @@ UTL_Scope::referenced (AST_Decl *e, // that was, and it can appear any number of times // in this scope without a clash. AST_Decl::NodeType nt = e->node_type (); - if (id->compare (*name_tmp) - && nt != AST_Decl::NT_module + if ( nt != AST_Decl::NT_module && nt != AST_Decl::NT_param_holder - && e->defined_in () == this) + && e->defined_in () == this + && id->compare (*name_tmp)) { idl_global->err ()->redef_error (id->get_string (), (*name_tmp)->get_string ()); return true; } // No clash if one or the other of the identifiers was escaped. - else if (id->case_compare_quiet (*name_tmp) - && !(id->escaped () ^ (*name_tmp)->escaped ())) + else if (!(id->escaped () ^ (*name_tmp)->escaped ()) + && id->case_compare_quiet (*name_tmp)) { if (idl_global->case_diff_error ()) { @@ -1997,24 +1939,19 @@ UTL_Scope::match_param (UTL_ScopedName *e) return 0; } - AST_Param_Holder *retval = 0; const char *name = e->first_component ()->get_string (); + FE_Utils::T_Param_Info *param = 0; for (FE_Utils::T_PARAMLIST_INFO::CONST_ITERATOR i (*params); - !i.done (); + i.next (param); i.advance ()) { - FE_Utils::T_Param_Info *param = 0; - i.next (param); - if (param->name_ == name) { - retval = - idl_global->gen ()->create_param_holder (e, param); - break; + return idl_global->gen ()->create_param_holder (e, param); } } - return retval; + return 0; } bool @@ -2055,12 +1992,11 @@ UTL_Scope::arg_specific_error (AST_Decl *t) AST_Argument *arg = AST_Argument::narrow_from_decl (t); AST_Argument::Direction d = arg->direction (); - AST_Operation::Flags flag = op->flags (); - /// Cannot add OUT or INOUT argument to oneway operation. + // Cannot add OUT or INOUT argument to oneway operation. if (( d == AST_Argument::dir_OUT || d == AST_Argument::dir_INOUT) - && flag == AST_Operation::OP_oneway) + && op->flags () == AST_Operation::OP_oneway) { idl_global->err ()->error2 (UTL_Error::EIDL_ONEWAY_CONFLICT, t, @@ -2068,9 +2004,8 @@ UTL_Scope::arg_specific_error (AST_Decl *t) return true; } + // This error is not caught in y.tab.cpp so we check for it here. AST_Type *arg_type = arg->field_type (); - - /// This error is not caught in y.tab.cpp so we check for it here. if ( arg_type->node_type () == AST_Decl::NT_array && arg_type->anonymous ()) { @@ -2084,14 +2019,14 @@ UTL_Scope::arg_specific_error (AST_Decl *t) void UTL_Scope::smart_local_add (AST_Decl *t) { - /// Catches struct, union * exception + // Catches struct, union * exception AST_Structure *s = AST_Structure::narrow_from_scope (this); - /// Catches AST_Field and AST_UnionBranch. + // Catches AST_Field and AST_UnionBranch. AST_Field *f = AST_Field::narrow_from_decl (t); - /// Decls inside a struct/union/exception are also referenced by - /// fields, and so must be handled differently. + // Decls inside a struct/union/exception are also referenced by + // fields, and so must be handled differently. if (s && !f) { this->add_to_local_types (t); @@ -2119,7 +2054,7 @@ UTL_Scope::smart_local_add (AST_Decl *t) } } -/// Determines if a name is global. +// Determines if a name is global. bool UTL_Scope::is_global_name (Identifier *i) { @@ -2129,12 +2064,7 @@ UTL_Scope::is_global_name (Identifier *i) } ACE_CString cmp (i->get_string (), 0, false); - if (cmp == "" || cmp == "::") - { - return true; - } - - return false; + return (cmp == "" || cmp == "::"); } AST_Decl * @@ -2176,14 +2106,8 @@ UTL_Scope::iter_lookup_by_name_local (AST_Decl *d, else { AST_Interface *i = AST_Interface::narrow_from_decl (d); - if (i) - { - result = i->look_in_inherited_local (e->head ()); - } - else - { - result = sc->look_in_prev_mods_local (e->head (), true); - } + result = i ? i->look_in_inherited_local (e->head ()) + : sc->look_in_prev_mods_local (e->head (), true); } UTL_ScopedName *sn = (UTL_ScopedName *) e->tail (); @@ -2205,48 +2129,6 @@ UTL_Scope::iter_lookup_by_name_local (AST_Decl *d, return result; } -AST_Decl * -UTL_Scope::local_checks (AST_Decl *d, bool full_def_only) -{ - AST_Decl *retval = 0; - - // 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! - AST_Decl::NodeType nt = d->node_type (); - 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 ( 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 (!AST_Template_Module_Ref::narrow_from_decl (d)) - { - // 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 |