summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsma <sma@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2010-05-26 13:20:45 +0000
committersma <sma@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2010-05-26 13:20:45 +0000
commit5545b139a33cf67f546e8d66324675910f27da99 (patch)
tree85246f0af3bc6b54a43e961b2e682ce9670025e5
parentc0160a5f3da4654fe79245bee4215e1f4fd783d1 (diff)
downloadATCD-5545b139a33cf67f546e8d66324675910f27da99.tar.gz
ChangeLogTag: Wed May 26 13:20:00 UTC 2010 Simon Massey <sma at prismtech dot com>
-rw-r--r--TAO/ChangeLog33
-rw-r--r--TAO/TAO_IDL/fe/idl.yy2
-rw-r--r--TAO/TAO_IDL/fe/lex.yy.cpp6
-rw-r--r--TAO/TAO_IDL/include/utl_scope.h122
-rw-r--r--TAO/TAO_IDL/include/utl_string.h41
-rw-r--r--TAO/TAO_IDL/util/utl_global.cpp2
-rw-r--r--TAO/TAO_IDL/util/utl_identifier.cpp43
-rw-r--r--TAO/TAO_IDL/util/utl_scope.cpp1233
-rw-r--r--TAO/TAO_IDL/util/utl_string.cpp253
9 files changed, 821 insertions, 914 deletions
diff --git a/TAO/ChangeLog b/TAO/ChangeLog
index ebb1308d993..c8e0740b58d 100644
--- a/TAO/ChangeLog
+++ b/TAO/ChangeLog
@@ -1,3 +1,36 @@
+Wed May 26 13:20:00 UTC 2010 Simon Massey <sma at prismtech dot com>
+
+ * TAO_IDL/include/utl_string.h:
+ * TAO_IDL/util/utl_string.cpp:
+
+ A huge amount of time was being wasted in very short lived
+ UTL_String objects. The UTL_String class was very badly
+ optomised for such heavy use given such short lifetimes of
+ the majority of it's use cases. Refactored, exposing it's
+ internal functions to make them available to external
+ const char * strings, which obviates the need for most of
+ the set-up, destruction and the multiple string allocations,
+ duplications and deallocations.
+
+ * TAO_IDL/include/utl_scope.h:
+ * TAO_IDL/util/utl_scope.cpp:
+
+ Refactored the UTL_ScopeActiveIterator class. This was biased
+ towards light set-up cost but heavy interation and dereferancing.
+ (The reverse requirement of its very tight loop use.) Set-up
+ now contains the logic to drive it whilst the iteration and
+ dereferaning costs are now a couple of statements each. Since
+ these are executed many times in the loop bodies, time savings
+ accrue rapidly. Also tidied up the layout and redundant variable
+ initialisations.
+
+ * TAO_IDL/fe/idl.yy:
+ * TAO_IDL/fe/lex.yy.cpp:
+ * TAO_IDL/util/utl_identifier.cpp:
+ * TAO_IDL/util/utl_global.cpp:
+
+ Updated due to changes to the utl_string class.
+
Wed May 26 10:10:33 UTC 2010 Vladimir Zykov <vladimir.zykov@prismtech.com>
* tests/Bug_3755_Ext_Regression/ziop_svc.conf:
diff --git a/TAO/TAO_IDL/fe/idl.yy b/TAO/TAO_IDL/fe/idl.yy
index 4155124cec7..7af14081bfe 100644
--- a/TAO/TAO_IDL/fe/idl.yy
+++ b/TAO/TAO_IDL/fe/idl.yy
@@ -6490,7 +6490,7 @@ formal_parameter_name
{
// formal_parameter_name : IDENTIFIER
ACE_NEW_RETURN ($$,
- UTL_String ($1),
+ UTL_String ($1, true),
1);
}
;
diff --git a/TAO/TAO_IDL/fe/lex.yy.cpp b/TAO/TAO_IDL/fe/lex.yy.cpp
index 7b5e96aeae0..858fc9ef19d 100644
--- a/TAO/TAO_IDL/fe/lex.yy.cpp
+++ b/TAO/TAO_IDL/fe/lex.yy.cpp
@@ -1692,7 +1692,7 @@ TAO_YY_RULE_SETUP
}
tmp[ACE_OS::strlen (tmp) - 1] = '\0';
ACE_NEW_RETURN (tao_yylval.sval,
- UTL_String (tmp + 1),
+ UTL_String (tmp + 1, true),
IDL_STRING_LITERAL);
return IDL_STRING_LITERAL;
}
@@ -2977,7 +2977,7 @@ idl_parse_line_and_file (char *buf)
if (temp_h) h = temp_h;
#endif
ACE_NEW (tmp,
- UTL_String (h));
+ UTL_String (h, true));
idl_global->update_prefix (tmp->get_string ());
idl_global->set_filename (tmp);
}
@@ -3025,7 +3025,7 @@ idl_parse_line_and_file (char *buf)
ACE_NEW (nm,
UTL_String (
idl_global->stripped_preproc_include (
- fname->get_string ())));
+ fname->get_string ()), true));
// This call also manages the #pragma prefix.
idl_global->store_include_file_name (nm);
diff --git a/TAO/TAO_IDL/include/utl_scope.h b/TAO/TAO_IDL/include/utl_scope.h
index 9dfff99a47d..c617360acb3 100644
--- a/TAO/TAO_IDL/include/utl_scope.h
+++ b/TAO/TAO_IDL/include/utl_scope.h
@@ -138,12 +138,22 @@ class UTL_ScopeActiveIterator;
class TAO_IDL_FE_Export UTL_Scope : public virtual COMMON_Base
{
+ // Friend class UTL_ScopeActiveIterator defines active iterator for
+ // UTL_Scope. Definition follows below.
+ friend class UTL_ScopeActiveIterator;
+ friend int tao_yyparse (void);
+ friend class AST_Enum;
+ friend class IDL_GlobalData;
+
public:
// Enum to denote the kind of iteration desired.
enum ScopeIterationKind {
IK_both // Iterate through both decls and local types.
, IK_decls // Iterate only through decls.
, IK_localtypes // Iterate only through local types.
+
+ // End users should not use this value directly
+ , IK_both_local // (Same as IK_both)
};
// Operations.
@@ -323,15 +333,7 @@ protected:
WHICH_PSEUDO which_pseudo_;
- // Friend class UTL_ScopeActiveIterator defines active iterator for
- // UTL_Scope. Definition follows below.
- friend class UTL_ScopeActiveIterator;
-
protected:
- friend int tao_yyparse (void);
- friend class AST_Enum;
- friend class IDL_GlobalData;
-
/// Scope Management Protocol.
/// Common code for most basic adding action.
@@ -517,39 +519,97 @@ private:
class TAO_IDL_FE_Export UTL_ScopeActiveIterator
{
public:
- // Operations.
+ // data members:
+ // Scope to iterate over.
+ UTL_Scope *source_;
- // Constructor.
- UTL_ScopeActiveIterator (UTL_Scope *s,
- UTL_Scope::ScopeIterationKind ik);
+ // What stage?
+ UTL_Scope::ScopeIterationKind stage_;
- // Advance to next item.
- void next (void);
+ // How many items left in this stage
+ unsigned long limit_;
- // Get current item.
- AST_Decl *item (void);
+ // The current item
+ AST_Decl **item_;
- // Have we iterated over entire scope?
- bool is_done (void);
+public:
+ // Constructors.
+ UTL_ScopeActiveIterator ()
+ : stage_ (UTL_Scope::IK_decls),
+ limit_ (0)
+ {}
- // What kind of iterator is this?
- UTL_Scope::ScopeIterationKind iteration_kind (void);
+ UTL_ScopeActiveIterator (UTL_Scope *s,
+ const UTL_Scope::ScopeIterationKind k)
+ : source_ (s),
+ stage_ ((UTL_Scope::IK_both == k && source_->pd_locals_used)
+ ? UTL_Scope::IK_both_local
+ : k),
+ limit_ ((UTL_Scope::IK_decls == stage_ ||
+ UTL_Scope::IK_both == stage_ )
+ ? source_->pd_decls_used
+ : source_->pd_locals_used),
+ item_ ((UTL_Scope::IK_decls == stage_ ||
+ UTL_Scope::IK_both == stage_ )
+ ? source_->pd_decls
+ : source_->pd_local_types)
+ {}
- // What stage are we in with this iterator?
- UTL_Scope::ScopeIterationKind iteration_stage (void);
+ // Advance to next item.
+ void next (void)
+ {
+ // If not done
+ if (this->limit_)
+ {
+ if (--this->limit_)
+ {
+ // Still more left, so advance to next item
+ ++this->item_;
+ }
+ // Out of data in this stage, move onto another?
+ else if (UTL_Scope::IK_both_local == this->stage_)
+ {
+ // Switch to next stage. Note that IK_both
+ // is the same as IK_decls but also notes
+ // that both types were being asked for!
+ this->stage_ = UTL_Scope::IK_both;
+ this->limit_ = this->source_->pd_decls_used;
+ this->item_ = source_->pd_decls;
+ }
+ }
+ }
-private:
- // Scope to iterate over.
- UTL_Scope *iter_source;
+ // Get the current item.
+ AST_Decl *item (void)
+ {
+ return (this->limit_) ? *this->item_ : 0;
+ }
- // What kind of iteration?
- UTL_Scope::ScopeIterationKind ik;
+ // Have we iterated over the entire scope?
+ bool is_done (void)
+ {
+ return !this->limit_;
+ }
- // What stage?
- UTL_Scope::ScopeIterationKind stage;
+ // What kind of iterator is this?
+ UTL_Scope::ScopeIterationKind iteration_kind (void)
+ {
+ return (UTL_Scope::IK_decls == this->stage_ ||
+ UTL_Scope::IK_localtypes == this->stage_ )
+ ? this->stage_
+ : UTL_Scope::IK_both;
+ }
- // What location in stage?
- long il;
+ // What stage are we at with this iterator?
+ UTL_Scope::ScopeIterationKind iteration_stage (void)
+ {
+ return (UTL_Scope::IK_decls == this->stage_ ||
+ UTL_Scope::IK_localtypes == this->stage_ )
+ ? this->stage_
+ : (UTL_Scope::IK_both == this->stage_)
+ ? UTL_Scope::IK_decls
+ : UTL_Scope::IK_localtypes;
+ }
};
#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
diff --git a/TAO/TAO_IDL/include/utl_string.h b/TAO/TAO_IDL/include/utl_string.h
index 1c9f70ff95c..c223c7db844 100644
--- a/TAO/TAO_IDL/include/utl_string.h
+++ b/TAO/TAO_IDL/include/utl_string.h
@@ -72,6 +72,7 @@ trademarks or registered trademarks of Sun Microsystems, Inc.
#include "ace/iosfwd.h"
/* Basic_Types.h are needed in QNX for size_t type. */
#include "ace/Basic_Types.h"
+#include "ace/SStringfwd.h"
class TAO_IDL_FE_Export UTL_String
{
@@ -82,16 +83,19 @@ class TAO_IDL_FE_Export UTL_String
public:
UTL_String (void);
- UTL_String (const char *str);
+ UTL_String (const char *str, bool take_copy= false);
UTL_String (UTL_String *s);
virtual ~UTL_String (void);
+ virtual void destroy (void);
+ // Cleanup function.
+
virtual void dump (ACE_OSTREAM_TYPE &o);
// Dump to the ostream.
- char *get_string (void);
+ char *get_string (void) {return this->p_str;}
// Get contents of utl_string.
char *get_canonical_rep (void);
@@ -104,22 +108,37 @@ public:
bool compare_quiet (UTL_String *s);
// Like the above but without error or warning message output.
- virtual void destroy (void);
- // Cleanup function.
+ static bool strcmp_caseless (
+ const char *lhs,
+ const char *rhs,
+ bool &mixed_case);
+ // Caseless string compare returns true if match, mixed_case is
+ // true if match only true due to ignoring case differences.
+
+ static bool compare (const char *lhs, const char *rhs);
+ // Compare two const char * (like the UTL_String compare)
+
+ static bool compare_quiet (const char *lhs, const char *rhs);
+ // Like the above but without error or warning message output.
+
+ static void get_canonical_rep (const char *src, char *dest);
+ // Get canonical representation. This is (implemented as) the all upper
+ // case corresponding string.
+
+ static void get_canonical_rep (ACE_CString &cstr);
+ // Get canonical representation. This is (implemented as) the all upper
+ // case corresponding string.
private:
// Data
+ bool copy_taken;
+ // If delete needs to be called on destroy/delete
+
char *p_str;
// Storage for characters.
char *c_str;
- // Canonicalized string
-
- size_t len;
- // How long is string.
-
- void canonicalize (void);
- // Compute canonical representation.
+ // Storage for canonicalized string.
};
#endif // _STRING_STRING_HH
diff --git a/TAO/TAO_IDL/util/utl_global.cpp b/TAO/TAO_IDL/util/utl_global.cpp
index 77d8310ec65..a4130d8c844 100644
--- a/TAO/TAO_IDL/util/utl_global.cpp
+++ b/TAO/TAO_IDL/util/utl_global.cpp
@@ -1898,7 +1898,7 @@ IDL_GlobalData::current_params (FE_Utils::T_PARAMLIST_INFO *params)
UTL_String *
IDL_GlobalData::utl_string_factory (const char *str)
{
- return new UTL_String (str);
+ return new UTL_String (str, true);
}
ACE_CString
diff --git a/TAO/TAO_IDL/util/utl_identifier.cpp b/TAO/TAO_IDL/util/utl_identifier.cpp
index 2829ee62d9e..baff5a6a2a7 100644
--- a/TAO/TAO_IDL/util/utl_identifier.cpp
+++ b/TAO/TAO_IDL/util/utl_identifier.cpp
@@ -159,11 +159,7 @@ Identifier::get_string (void)
void
Identifier::replace_string (const char * s)
{
- if (this->pv_string != 0)
- {
- delete [] this->pv_string;
- }
-
+ delete [] this->pv_string;
this->pv_string = ACE::strnew (s);
}
@@ -171,52 +167,29 @@ Identifier::replace_string (const char * s)
bool
Identifier::compare (Identifier *o)
{
- if (o == 0)
- {
- return false;
- };
-
- if (this->pv_string == 0 || o->get_string () == 0)
+ if (!o ||
+ !o->pv_string ||
+ !this->pv_string ||
+ this->escaped_ ^ o->escaped_)
{
return false;
}
- if (this->escaped_ ^ o->escaped_)
- {
- return false;
- }
-
- return (ACE_OS::strcmp (this->pv_string, o->get_string ()) == 0);
+ return !ACE_OS::strcmp (this->pv_string, o->pv_string);
}
// Report the appropriate error if the two identifiers differ only in case.
bool
Identifier::case_compare (Identifier *o)
{
- UTL_String member (this->pv_string);
- UTL_String other (o->get_string ());
-
- bool result = member.compare (&other);
-
- member.destroy ();
- other.destroy ();
-
- return result;
+ return UTL_String::compare (this->pv_string, o->pv_string);
}
// Report no error if the two identifiers differ only in case.
bool
Identifier::case_compare_quiet (Identifier *o)
{
- UTL_String member (this->pv_string);
- UTL_String other (o->pv_string);
-
- bool const result = member.compare_quiet (&other);
-
- member.destroy ();
- other.destroy ();
-
- return result;
+ return UTL_String::compare_quiet (this->pv_string, o->pv_string);
}
Identifier *
diff --git a/TAO/TAO_IDL/util/utl_scope.cpp b/TAO/TAO_IDL/util/utl_scope.cpp
index 288cb29ef0f..c926b40fbe7 100644
--- a/TAO/TAO_IDL/util/utl_scope.cpp
+++ b/TAO/TAO_IDL/util/utl_scope.cpp
@@ -160,6 +160,67 @@ UTL_Scope::UTL_Scope (AST_Decl::NodeType nt)
// Destructor.
UTL_Scope::~UTL_Scope (void)
{
+ for (UTL_ScopeActiveIterator iter (this, IK_both);
+ !iter.is_done ();
+ iter.next ())
+ {
+ AST_Decl *d = iter.item ();
+ d->destroy ();
+ delete d;
+ }
+
+ delete [] this->pd_decls;
+ delete [] this->pd_local_types;
+ delete [] this->pd_referenced;
+
+ for (long i = this->pd_name_referenced_used; i--;) // NOTE test with i--
+ {
+ Identifier *id = this->pd_name_referenced[i];
+ id->destroy ();
+ delete id;
+ }
+
+ delete [] this->pd_name_referenced;
+}
+
+void
+UTL_Scope::destroy (void)
+{
+ for (UTL_ScopeActiveIterator iter (this, IK_both);
+ !iter.is_done ();
+ iter.next ())
+ {
+ AST_Decl *d = iter.item ();
+ d->destroy ();
+ delete d;
+ }
+
+ delete [] this->pd_decls;
+ this->pd_decls = 0;
+ this->pd_decls_allocated = 0;
+ this->pd_decls_used = 0;
+
+ delete [] this->pd_local_types;
+ this->pd_local_types = 0;
+ this->pd_locals_allocated = 0;
+ this->pd_locals_used = 0;
+
+ delete [] this->pd_referenced;
+ this->pd_referenced = 0;
+ this->pd_referenced_allocated = 0;
+ this->pd_referenced_used = 0;
+
+ for (long i = this->pd_name_referenced_used; i--;) // NOTE test with i--
+ {
+ Identifier *id = this->pd_name_referenced[i];
+ id->destroy ();
+ delete id;
+ }
+
+ delete [] this->pd_name_referenced;
+ this->pd_name_referenced = 0;
+ this->pd_name_referenced_allocated = 0;
+ this->pd_name_referenced_used = 0;
}
// Protected operations.
@@ -170,14 +231,13 @@ UTL_Scope::~UTL_Scope (void)
AST_Decl *
UTL_Scope::lookup_for_add (AST_Decl *d)
{
- if (d == 0)
+ if (!d)
{
return 0;
}
Identifier *id = d->local_name ();
-
- if (this->idl_keyword_clash (id) != 0)
+ if (this->idl_keyword_clash (id))
{
return 0;
}
@@ -193,19 +253,13 @@ UTL_Scope::idl_keyword_clash (Identifier *e)
return 0;
}
+ // Convert the identifier string into a
+ // canonical (uppercase) form as a ACE_CString
char *tmp = e->get_string ();
+ ACE_CString ext_id (tmp);
+ UTL_String::get_canonical_rep (ext_id);
- UTL_String utl_tmp (tmp);
-
- ACE_CString ext_id (utl_tmp.get_canonical_rep (),
- 0,
- false);
-
- int status = idl_global->idl_keywords ().find (ext_id);
-
- utl_tmp.destroy ();
-
- if (status == 0)
+ if (!idl_global->idl_keywords ().find (ext_id))
{
if (idl_global->case_diff_error ())
{
@@ -228,36 +282,47 @@ UTL_Scope::redef_clash (AST_Decl::NodeType new_nt,
{
switch (new_nt)
{
- 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_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_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_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_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_eventtype_fwd:
- return (scope_elem_nt != AST_Decl::NT_eventtype_fwd
- && scope_elem_nt != AST_Decl::NT_eventtype);
- default:
- return true;
+ 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_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_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_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_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_eventtype_fwd:
+ return ( scope_elem_nt != AST_Decl::NT_eventtype_fwd
+ && scope_elem_nt != AST_Decl::NT_eventtype);
+
+ default:
+ return true;
}
}
@@ -279,17 +344,19 @@ UTL_Scope::check_for_predef_seq (AST_Decl *d)
// We are interested only in members, arguments and typedefs.
switch (nt)
{
- case AST_Decl::NT_field:
- case AST_Decl::NT_union_branch:
- case AST_Decl::NT_attr:
- case AST_Decl::NT_argument:
- bt = AST_Field::narrow_from_decl (d)->field_type ();
- break;
- case AST_Decl::NT_typedef:
- bt = AST_Typedef::narrow_from_decl (d)->base_type ();
- break;
- default:
- return;
+ case AST_Decl::NT_field:
+ case AST_Decl::NT_union_branch:
+ case AST_Decl::NT_attr:
+ case AST_Decl::NT_argument:
+ bt = AST_Field::narrow_from_decl (d)->field_type ();
+ break;
+
+ case AST_Decl::NT_typedef:
+ bt = AST_Typedef::narrow_from_decl (d)->base_type ();
+ break;
+
+ default:
+ return;
}
// Check to eliminate more candidates.
@@ -309,7 +376,7 @@ UTL_Scope::check_for_predef_seq (AST_Decl *d)
// Must be defined in the CORBA module.
AST_Decl *p = ScopeAsDecl (bt->defined_in ());
- if (ACE_OS::strcmp (p->local_name ()->get_string (), "CORBA") != 0)
+ if (ACE_OS::strcmp (p->local_name ()->get_string (), "CORBA"))
{
return;
}
@@ -324,7 +391,8 @@ UTL_Scope::check_for_predef_seq (AST_Decl *d)
idl_global->string_seq_seen_ = true;
return;
}
- else if (nt == AST_Decl::NT_wstring)
+
+ if (nt == AST_Decl::NT_wstring)
{
idl_global->wstring_seq_seen_ = true;
return;
@@ -332,61 +400,73 @@ UTL_Scope::check_for_predef_seq (AST_Decl *d)
// Now check for predefined base type.
AST_PredefinedType *pdt = AST_PredefinedType::narrow_from_decl (bt);
- if (pdt == 0)
+ if (!pdt)
{
return;
}
switch (pdt->pt ())
{
- case AST_PredefinedType::PT_long:
- idl_global->long_seq_seen_ = true;
- break;
- case AST_PredefinedType::PT_ulong:
- idl_global->ulong_seq_seen_ = true;
- break;
- case AST_PredefinedType::PT_longlong:
- idl_global->longlong_seq_seen_ = true;
- break;
- case AST_PredefinedType::PT_ulonglong:
- idl_global->ulonglong_seq_seen_ = true;
- break;
- case AST_PredefinedType::PT_short:
- idl_global->short_seq_seen_ = true;
- break;
- case AST_PredefinedType::PT_ushort:
- idl_global->ushort_seq_seen_ = true;
- break;
- case AST_PredefinedType::PT_float:
- idl_global->float_seq_seen_ = true;
- break;
- case AST_PredefinedType::PT_double:
- idl_global->double_seq_seen_ = true;
- break;
- case AST_PredefinedType::PT_longdouble:
- idl_global->longdouble_seq_seen_ = true;
- break;
- case AST_PredefinedType::PT_char:
- idl_global->char_seq_seen_ = true;
- break;
- case AST_PredefinedType::PT_wchar:
- idl_global->wchar_seq_seen_ = true;
- break;
- case AST_PredefinedType::PT_boolean:
- idl_global->boolean_seq_seen_ = true;
- break;
- case AST_PredefinedType::PT_octet:
- idl_global->octet_seq_seen_ = true;
- break;
- case AST_PredefinedType::PT_any:
- idl_global->any_seq_seen_ = true;
- break;
- default:
- break;
- }
-}
-
-// Public operations.
+ case AST_PredefinedType::PT_long:
+ idl_global->long_seq_seen_ = true;
+ break;
+
+ case AST_PredefinedType::PT_ulong:
+ idl_global->ulong_seq_seen_ = true;
+ break;
+
+ case AST_PredefinedType::PT_longlong:
+ idl_global->longlong_seq_seen_ = true;
+ break;
+
+ case AST_PredefinedType::PT_ulonglong:
+ idl_global->ulonglong_seq_seen_ = true;
+ break;
+
+ case AST_PredefinedType::PT_short:
+ idl_global->short_seq_seen_ = true;
+ break;
+
+ case AST_PredefinedType::PT_ushort:
+ idl_global->ushort_seq_seen_ = true;
+ break;
+
+ case AST_PredefinedType::PT_float:
+ idl_global->float_seq_seen_ = true;
+ break;
+
+ case AST_PredefinedType::PT_double:
+ idl_global->double_seq_seen_ = true;
+ break;
+
+ case AST_PredefinedType::PT_longdouble:
+ idl_global->longdouble_seq_seen_ = true;
+ break;
+
+ case AST_PredefinedType::PT_char:
+ idl_global->char_seq_seen_ = true;
+ break;
+
+ case AST_PredefinedType::PT_wchar:
+ idl_global->wchar_seq_seen_ = true;
+ break;
+
+ case AST_PredefinedType::PT_boolean:
+ idl_global->boolean_seq_seen_ = true;
+ break;
+
+ case AST_PredefinedType::PT_octet:
+ idl_global->octet_seq_seen_ = true;
+ break;
+
+ case AST_PredefinedType::PT_any:
+ idl_global->any_seq_seen_ = true;
+ break;
+
+ default:
+ break;
+ }
+}
// Protected Front End Scope Management Protocol.
//
@@ -398,26 +478,25 @@ UTL_Scope::check_for_predef_seq (AST_Decl *d)
AST_Decl *
UTL_Scope::fe_add_decl (AST_Decl *t)
{
- AST_Decl *d = 0;
-
// Already defined and cannot be redefined? Or already used?
- if ((d = this->lookup_for_add (t)) != 0)
+ AST_Decl *d = this->lookup_for_add (t);
+ if (d)
{
if (!can_be_redefined (d))
{
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).
bool inherited_factory =
- (tnt == AST_Decl::NT_factory
+ ( tnt == AST_Decl::NT_factory
&& dnt == AST_Decl::NT_factory
&& t->defined_in () != d->defined_in ());
-
+
if (!inherited_factory)
- {
+ {
idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
t,
ScopeAsDecl (this),
@@ -425,31 +504,27 @@ UTL_Scope::fe_add_decl (AST_Decl *t)
return 0;
}
}
-
+
/// 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 ();
-
bool need_ref_check =
- (lnt != AST_Decl::NT_module
+ ( lnt != AST_Decl::NT_module
|| ant != AST_Decl::NT_module);
- if (need_ref_check)
+ if (need_ref_check && this->referenced (d, t->local_name ()))
{
- if (this->referenced (d, t->local_name ()))
- {
- idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
- t,
- ScopeAsDecl (this),
- d);
- return 0;
- }
+ idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
+ t,
+ ScopeAsDecl (this),
+ d);
+ return 0;
}
if (t->has_ancestor (d))
@@ -462,12 +537,12 @@ UTL_Scope::fe_add_decl (AST_Decl *t)
{
return 0;
}
-
+
if (this->arg_specific_error (t))
{
return 0;
}
-
+
this->smart_local_add (t);
// Add it to set of locally referenced symbols, unless it is
@@ -487,25 +562,22 @@ AST_Field *
UTL_Scope::fe_add_ref_decl (AST_Field *t)
{
AST_Decl *d = this->fe_add_decl (t);
-
- if (d != 0)
+ if (d)
{
AST_Type *ft = t->field_type ();
UTL_ScopedName *mru = ft->last_referenced_as ();
-
- if (mru != 0)
+ if (mru)
{
this->add_to_referenced (ft,
false,
mru->first_component ());
}
}
-
+
/// Catches struct/union/exception which all maintain a queue
- /// for fields as distinct from decls and enum values.
+ /// for fields as distinct from decls and enum values.
AST_Structure *s = AST_Structure::narrow_from_scope (this);
-
- if (s != 0)
+ if (s)
{
s->fields ().enqueue_tail (t);
}
@@ -516,9 +588,8 @@ UTL_Scope::fe_add_ref_decl (AST_Field *t)
AST_Structure *
UTL_Scope::fe_add_full_struct_type (AST_Structure *t)
{
- AST_Decl *predef = 0;
-
- if ((predef = this->lookup_for_add (t)) != 0)
+ AST_Decl *predef = this->lookup_for_add (t);
+ if (predef)
{
if (!can_be_redefined (predef))
{
@@ -526,26 +597,23 @@ UTL_Scope::fe_add_full_struct_type (AST_Structure *t)
t,
ScopeAsDecl (this),
predef);
-
return 0;
}
- else if (referenced (predef, t->local_name ())
- && !t->is_defined ())
+ if (referenced (predef, t->local_name ()) && !t->is_defined ())
{
idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
t,
ScopeAsDecl (this),
predef);
-
return 0;
}
}
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.
- if (nt == AST_Decl::NT_struct
+ if ( nt == AST_Decl::NT_struct
|| nt == AST_Decl::NT_union
|| nt == AST_Decl::NT_except)
{
@@ -560,17 +628,15 @@ UTL_Scope::fe_add_full_struct_type (AST_Structure *t)
this->add_to_referenced (t,
false,
t->local_name ());
-
return t;
}
AST_StructureFwd *
UTL_Scope::fe_add_fwd_struct_type (AST_StructureFwd *t)
{
- AST_Decl *d = 0;
-
// Already defined and cannot be redefined? Or already used?
- if ((d = this->lookup_for_add (t)) != 0)
+ AST_Decl *d = this->lookup_for_add (t);
+ if (d)
{
AST_Decl::NodeType nt = d->node_type ();
@@ -585,25 +651,21 @@ UTL_Scope::fe_add_fwd_struct_type (AST_StructureFwd *t)
AST_Structure *s = AST_Structure::narrow_from_decl (d);
t->set_full_definition (s);
}
- else
+ else if (!can_be_redefined (d))
{
- if (!can_be_redefined (d))
- {
- idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
- t,
- ScopeAsDecl (this),
- d);
- return 0;
- }
-
- if (this->referenced (d, t->local_name ()))
- {
- idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
- t,
- ScopeAsDecl (this),
- d);
- return 0;
- }
+ idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
+ t,
+ ScopeAsDecl (this),
+ d);
+ return 0;
+ }
+ else if (this->referenced (d, t->local_name ()))
+ {
+ idl_global->err ()->error3 (UTL_Error::EIDL_DEF_USE,
+ t,
+ ScopeAsDecl (this),
+ d);
+ return 0;
}
}
@@ -902,78 +964,53 @@ UTL_Scope::lookup_pseudo (Identifier *e)
return 0;
}
- Identifier *item_name = 0;
- AST_Decl *d = 0;
+ bool *seen = 0;
+ UTL_Scope *start_scope = this;
char *name_string = e->get_string ();
-
- if (ACE_OS::strcasecmp (name_string, "Object") == 0)
- {
- this->which_pseudo_ = PSEUDO_OBJECT;
- }
- else if (ACE_OS::strcasecmp (name_string, "ValueBase") == 0)
- {
- this->which_pseudo_ = PSEUDO_VALUEBASE;
- }
- else if (ACE_OS::strcasecmp (name_string, "AbstractBase") == 0)
- {
- this->which_pseudo_ = PSEUDO_ABSTRACTBASE;
- }
- else if (ACE_OS::strcasecmp (name_string, "TypeCode") == 0
- || ACE_OS::strcasecmp (name_string, "TCKind") == 0)
+ if ( !ACE_OS::strcasecmp (name_string, "TypeCode")
+ || !ACE_OS::strcasecmp (name_string, "TCKind"))
{
this->which_pseudo_ = PSEUDO_TYPECODE;
+ seen = &idl_global->typecode_seen_;
}
else
{
- return 0;
+ start_scope = idl_global->root ();
+
+ if (!ACE_OS::strcasecmp (name_string, "Object"))
+ {
+ this->which_pseudo_ = PSEUDO_OBJECT;
+ seen = &idl_global->base_object_seen_;
+ }
+ else if (!ACE_OS::strcasecmp (name_string, "ValueBase"))
+ {
+ this->which_pseudo_ = PSEUDO_VALUEBASE;
+ seen = &idl_global->valuebase_seen_;
+ }
+ else if (!ACE_OS::strcasecmp (name_string, "AbstractBase"))
+ {
+ this->which_pseudo_ = PSEUDO_ABSTRACTBASE;
+ seen = &idl_global->abstractbase_seen_;
+ }
+ else
+ {
+ return 0;
+ }
}
-
- UTL_Scope *start_scope = 0;
- switch (this->which_pseudo_)
- {
- case PSEUDO_TYPECODE:
- start_scope = this;
- break;
- case PSEUDO_OBJECT:
- case PSEUDO_VALUEBASE:
- case PSEUDO_ABSTRACTBASE:
- start_scope = idl_global->root ();
- break;
- default:
- break;
- }
-
- for (UTL_ScopeActiveIterator i (start_scope, UTL_Scope::IK_decls);
+ for (UTL_ScopeActiveIterator i (start_scope, IK_decls);
!i.is_done ();
i.next ())
{
- d = i.item ();
- item_name = d->local_name ();
-
+ AST_Decl *d = i.item ();
+ Identifier *item_name = d->local_name ();
if (e->case_compare (item_name))
{
// These have to be located here because we are just looking
// up a scoped name - skip for imported nodes.
if (idl_global->in_main_file ())
{
- switch (this->which_pseudo_)
- {
- case PSEUDO_TYPECODE:
- idl_global->typecode_seen_ = true;
- break;
- case PSEUDO_OBJECT:
- idl_global->base_object_seen_ = true;
- break;
- case PSEUDO_VALUEBASE:
- idl_global->valuebase_seen_ = true;
- break;
- case PSEUDO_ABSTRACTBASE:
- idl_global->abstractbase_seen_ = true;
- break;
- default:
- break;
- }
+ *seen = true;
}
return d;
@@ -982,13 +1019,12 @@ UTL_Scope::lookup_pseudo (Identifier *e)
if (this->which_pseudo_ == PSEUDO_TYPECODE)
{
- d = this->look_in_prev_mods_local (e);
-
- if (d != 0)
+ AST_Decl *d = this->look_in_prev_mods_local (e);
+ if (d)
{
// Generation of #includes for Typecode.h
// checks this bit, so we set it for TCKind as well.
- idl_global->typecode_seen_ = true;
+ *seen = true;
return d;
}
}
@@ -1014,72 +1050,85 @@ UTL_Scope::special_lookup (UTL_ScopedName *,
AST_Decl *
UTL_Scope::lookup_primitive_type (AST_Expression::ExprType et)
{
- AST_PredefinedType::PredefinedType pdt;
-
AST_Decl *as_decl = ScopeAsDecl (this);
-
- if (as_decl == 0)
+ if (!as_decl)
{
return 0;
}
UTL_Scope *ancestor = as_decl->defined_in ();
-
- if (ancestor != 0)
+ if (ancestor)
{
return ancestor->lookup_primitive_type (et);
}
+ AST_PredefinedType::PredefinedType pdt;
switch (et)
{
case AST_Expression::EV_short:
pdt = AST_PredefinedType::PT_short;
break;
+
case AST_Expression::EV_ushort:
pdt = AST_PredefinedType::PT_ushort;
break;
+
case AST_Expression::EV_long:
pdt = AST_PredefinedType::PT_long;
break;
+
case AST_Expression::EV_ulong:
pdt = AST_PredefinedType::PT_ulong;
break;
+
case AST_Expression::EV_longlong:
pdt = AST_PredefinedType::PT_longlong;
break;
+
case AST_Expression::EV_ulonglong:
pdt = AST_PredefinedType::PT_ulonglong;
break;
+
case AST_Expression::EV_float:
pdt = AST_PredefinedType::PT_float;
break;
+
case AST_Expression::EV_double:
pdt = AST_PredefinedType::PT_double;
break;
+
case AST_Expression::EV_longdouble:
pdt = AST_PredefinedType::PT_longdouble;
break;
+
case AST_Expression::EV_char:
pdt = AST_PredefinedType::PT_char;
break;
+
case AST_Expression::EV_wchar:
pdt = AST_PredefinedType::PT_wchar;
break;
+
case AST_Expression::EV_octet:
pdt = AST_PredefinedType::PT_octet;
break;
+
case AST_Expression::EV_bool:
pdt = AST_PredefinedType::PT_boolean;
break;
+
case AST_Expression::EV_any:
pdt = AST_PredefinedType::PT_any;
break;
+
case AST_Expression::EV_object:
pdt = AST_PredefinedType::PT_object;
break;
+
case AST_Expression::EV_void:
pdt = AST_PredefinedType::PT_void;
break;
+
case AST_Expression::EV_enum:
case AST_Expression::EV_string:
case AST_Expression::EV_wstring:
@@ -1088,37 +1137,31 @@ UTL_Scope::lookup_primitive_type (AST_Expression::ExprType et)
return 0;
}
- AST_PredefinedType *t = 0;
-
- for (UTL_ScopeActiveIterator i (this, UTL_Scope::IK_decls);
+ for (UTL_ScopeActiveIterator i (this, IK_decls);
!i.is_done();
i.next ())
{
as_decl = i.item ();
-
if (as_decl->node_type () == AST_Decl::NT_pre_defined)
{
- t = AST_PredefinedType::narrow_from_decl (as_decl);
-
- if (t == 0)
- {
- continue;
- }
-
- if (t->pt () == pdt)
+ AST_PredefinedType *t =
+ AST_PredefinedType::narrow_from_decl (as_decl);
+ if (t && t->pt () == pdt)
{
if (idl_global->in_main_file ())
{
switch (pdt)
{
- case AST_PredefinedType::PT_any:
- idl_global->any_seen_ = true;
- break;
- case AST_PredefinedType::PT_object:
- idl_global->base_object_seen_ = true;
- break;
- default:
- break;
+ case AST_PredefinedType::PT_any:
+ idl_global->any_seen_ = true;
+ break;
+
+ case AST_PredefinedType::PT_object:
+ idl_global->base_object_seen_ = true;
+ break;
+
+ default:
+ break;
}
}
@@ -1150,125 +1193,113 @@ AST_Decl *
UTL_Scope::lookup_by_name_local (Identifier *e,
bool full_def_only)
{
- AST_Decl *d = 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);
-
- if (d != 0)
+ AST_Decl *d = this->lookup_pseudo (e);
+ if (d)
{
return d;
}
- if (this->idl_keyword_clash (e) != 0)
+ if (this->idl_keyword_clash (e))
{
return 0;
}
- Identifier *item_name = 0;
-
- bool in_corba =
- ACE_OS::strcmp (e->get_string (), "CORBA") == 0;
+ bool in_corba = !ACE_OS::strcmp (e->get_string (), "CORBA");
// We search only the decls here, the local types are done
// below as a last resort.
- for (UTL_ScopeActiveIterator i (this, UTL_Scope::IK_decls);
+ for (UTL_ScopeActiveIterator i (this, IK_decls);
!i.is_done ();
i.next ())
{
AST_Decl *tmp = i.item ();
- item_name = tmp->local_name ();
-
- if (item_name == 0)
- {
- continue;
- }
+ 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.
- if (!in_corba
- && ACE_OS::strcmp (tmp->name ()->head ()->get_string (), "CORBA") == 0)
+ && (in_corba || ACE_OS::strcmp (tmp->name ()->head ()->get_string (), "CORBA"))
+ && e->case_compare (item_name))
{
- continue;
- }
+ if (AST_Template_Module_Ref::narrow_from_decl (tmp))
+ {
+ // 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;
+ }
- if (e->case_compare (item_name))
- {
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_interface_fwd
- || nt == AST_Decl::NT_valuetype_fwd
- || nt == AST_Decl::NT_component_fwd
- || nt == AST_Decl::NT_eventtype_fwd)
+ if ( nt == AST_Decl::NT_struct_fwd
+ || nt == AST_Decl::NT_union_fwd)
{
- d = AST_InterfaceFwd::narrow_from_decl (d)->full_definition ();
+ d = AST_StructureFwd::narrow_from_decl (tmp)->full_definition ();
}
- else if (nt == AST_Decl::NT_struct_fwd
- || nt == AST_Decl::NT_union_fwd)
+ 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_StructureFwd::narrow_from_decl (d)->full_definition ();
- }
-
- if (AST_Template_Module_Ref::narrow_from_decl (d) != 0)
- {
- // 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;
+ d = AST_InterfaceFwd::narrow_from_decl (tmp)->full_definition ();
}
+
+ break; // We have found the one and only one we are looking for.
}
}
- if (d == 0)
+ if (!d)
{
AST_Module *m = AST_Module::narrow_from_scope (this);
-
- if (m != 0)
+ if (m)
{
d = m->look_in_prev_mods_local (e);
-
- if (0 != d && full_def_only && !d->is_defined ())
+ if (d && full_def_only && !d->is_defined ())
{
d = 0;
}
}
+ else
+ {
+ AST_Interface *i =
+ AST_Interface::narrow_from_scope (this);
+ if (i)
+ {
+ d = i->look_in_inherited_local (e);
+ }
+ }
}
-
- if (d == 0)
- {
- AST_Interface *i =
- AST_Interface::narrow_from_scope (this);
-
- if (i != 0)
- {
- d = i->look_in_inherited_local (e);
- }
- }
-
+
/// 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 == 0)
+ if (!d)
{
- for (UTL_ScopeActiveIterator i (this, UTL_Scope::IK_localtypes);
+ for (UTL_ScopeActiveIterator i (this, IK_localtypes);
!i.is_done ();
i.next ())
{
AST_Decl *l = i.item ();
-
if (e->case_compare (l->local_name ()))
{
d = l;
@@ -1276,7 +1307,7 @@ UTL_Scope::lookup_by_name_local (Identifier *e,
}
}
}
-
+
return d;
}
@@ -1285,50 +1316,47 @@ UTL_Scope::lookup_by_name (UTL_ScopedName *e,
bool full_def_only)
{
/// Empty name? Exit immediately.
- if (e == 0)
+ if (!e)
{
return 0;
}
-
+
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.
- bool global_scope_name =
- this->is_global_name (e->head ());
-
+ const bool global_scope_name = this->is_global_name (e->head ());
if (global_scope_name)
{
work_name = static_cast<UTL_ScopedName *> (e->tail ());
work_scope = 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 =
+
+ 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 == 0 && outer != 0)
+ /// try to match the rest of the scoped name.
+ while (!d && outer)
{
d = outer->lookup_by_name_r (work_name, full_def_only);
-
+
AST_Decl *s = ScopeAsDecl (outer);
outer = s->defined_in ();
}
-
- if (!global_scope_name && d != 0)
+
+ if (!global_scope_name && d)
{
- ACE_CDR::ULong slot = 0UL;
- const char *head = e->head ()->get_string ();
+ 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)
@@ -1338,26 +1366,19 @@ UTL_Scope::lookup_by_name (UTL_ScopedName *e,
/// The first queue item (last enqueued) will always
/// match e->head(), but does not indicate an error.
- if (slot == 0UL)
+ if (!slot)
{
outer_scope = *item;
continue;
}
-
- const char *lname =
- (*item)->local_name ()->get_string ();
-
- if (ACE_OS::strcmp (lname, head) == 0)
+
+ const char *lname = (*item)->local_name ()->get_string ();
+ if (!ACE_OS::strcmp (lname, head)
+ && !(*item)->masking_checks (outer_scope))
{
- if (!(*item)->masking_checks (outer_scope))
- {
- idl_global->err ()->scope_masking_error (
- d,
- (*item));
-
- d = 0;
- break;
- }
+ idl_global->err ()->scope_masking_error (d, *item);
+ d = 0;
+ break;
}
}
}
@@ -1370,21 +1391,17 @@ AST_Decl *
UTL_Scope::lookup_by_name_r (UTL_ScopedName *e,
bool full_def_only)
{
- AST_Decl *d = 0;
- AST_Decl *tmp = 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)
+ AST_Decl *d = this->lookup_pseudo (e->head ());
+ if (d)
{
return d;
}
- if (this->idl_keyword_clash (e->head ()) != 0)
+ if (this->idl_keyword_clash (e->head ()))
{
return 0;
}
@@ -1397,42 +1414,39 @@ UTL_Scope::lookup_by_name_r (UTL_ScopedName *e,
{
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)
+ // lookup.
+ if (param_holder)
{
return param_holder;
}
}
- bool in_corba =
- ACE_OS::strcmp (e->head ()->get_string (), "CORBA") == 0;
-
- for (UTL_ScopeActiveIterator i (this, UTL_Scope::IK_decls);
+ bool in_corba = !ACE_OS::strcmp (e->head ()->get_string (), "CORBA");
+ for (UTL_ScopeActiveIterator i (this, IK_decls);
!i.is_done ();
i.next ())
{
- tmp = i.item ();
+ 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") == 0)
+ && !ACE_OS::strcmp (tmp->name ()->head ()->get_string (), "CORBA"))
{
continue;
}
-
+
if (tmp->local_name ()->case_compare (e->head ()))
{
d = tmp;
-
if (e->length () == 1)
{
d = this->local_checks (d, full_def_only);
@@ -1440,37 +1454,34 @@ UTL_Scope::lookup_by_name_r (UTL_ScopedName *e,
else
{
UTL_Scope *s = DeclAsScope (d);
-
- if (s != 0)
+ if (s)
{
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);
}
}
}
}
-
+
/// 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);
+ for (UTL_ScopeActiveIterator i (this, IK_localtypes);
!i.is_done ();
i.next ())
{
AST_Decl *tmp = i.item ();
-
if (tmp->local_name ()->case_compare (e->head ()))
{
d = tmp;
break;
}
}
-
- if (d == 0)
+
+ if (!d)
{
d = this->special_lookup (e, full_def_only);
}
@@ -1485,27 +1496,20 @@ UTL_Scope::add_to_referenced (AST_Decl *e,
Identifier *id,
AST_Decl *ex)
{
- UTL_Scope *s = 0;
- AST_Decl **tmp;
- AST_Interface *itf = 0;
- long oreferenced_allocated;
- long i;
-
- if (e == 0)
+ if (!e)
{
return;
}
- AST_Decl::NodeType nt = e->node_type ();
-
// Special case for forward declared interfaces in the
// scope in which they're defined. Cannot add before full
// definition is seen.
- if (nt == AST_Decl::NT_interface || nt == AST_Decl::NT_component)
+ AST_Decl::NodeType nt = e->node_type ();
+ if ( nt == AST_Decl::NT_interface
+ || nt == AST_Decl::NT_component)
{
- itf = AST_Interface::narrow_from_decl (e);
-
- if (itf != 0
+ AST_Interface *itf = AST_Interface::narrow_from_decl (e);
+ if (itf
&& itf->defined_in () == this
&& !itf->is_defined ())
{
@@ -1525,13 +1529,13 @@ UTL_Scope::add_to_referenced (AST_Decl *e,
// Make sure there's space for one more decl.
if (this->pd_referenced_allocated == this->pd_referenced_used)
{
- oreferenced_allocated = this->pd_referenced_allocated;
- pd_referenced_allocated += INCREMENT;
+ long oreferenced_allocated = this->pd_referenced_allocated;
+ this->pd_referenced_allocated += INCREMENT;
- ACE_NEW (tmp,
- AST_Decl *[this->pd_referenced_allocated]);
+ AST_Decl **tmp = 0;
+ ACE_NEW (tmp, AST_Decl *[this->pd_referenced_allocated]);
- for (i = 0; i < oreferenced_allocated; i++)
+ for (long i = 0; i < oreferenced_allocated; ++i)
{
tmp[i] = this->pd_referenced[i];
}
@@ -1541,13 +1545,13 @@ UTL_Scope::add_to_referenced (AST_Decl *e,
}
// Insert new reference.
- if (ex == 0)
+ if (!ex)
{
- this->pd_referenced[this->pd_referenced_used++] = e;
+ this->pd_referenced [this->pd_referenced_used++] = e;
}
else if (this->referenced (ex))
{
- for (i = this->pd_referenced_used; i > 0; i--)
+ for (long i = this->pd_referenced_used; 0 < i; --i)
{
this->pd_referenced[i] = this->pd_referenced[i - 1];
@@ -1558,7 +1562,7 @@ UTL_Scope::add_to_referenced (AST_Decl *e,
}
}
- if (this->pd_referenced_used > 0)
+ if (0 < this->pd_referenced_used)
{
++this->pd_referenced_used;
}
@@ -1569,13 +1573,10 @@ UTL_Scope::add_to_referenced (AST_Decl *e,
// add "e" to the set of referenced nodes in the parent of "this".
if (recursive && !(e->has_ancestor (ScopeAsDecl (this))))
{
- s = e->defined_in ();
-
- if (s != 0)
+ UTL_Scope *s = e->defined_in ();
+ if (s)
{
- s->add_to_referenced (e,
- recursive,
- id);
+ s->add_to_referenced (e, recursive, id);
}
}
@@ -1593,13 +1594,12 @@ UTL_Scope::add_to_name_referenced (Identifier *id)
if (this->pd_name_referenced_allocated == this->pd_name_referenced_used)
{
long name_referenced_allocated = this->pd_name_referenced_allocated;
- pd_name_referenced_allocated += INCREMENT;
+ this->pd_name_referenced_allocated += INCREMENT;
Identifier **name_tmp = 0;
- ACE_NEW (name_tmp,
- Identifier *[this->pd_name_referenced_allocated]);
+ ACE_NEW (name_tmp, Identifier *[this->pd_name_referenced_allocated]);
- for (long i = 0; i < name_referenced_allocated; i++)
+ for (long i = 0; i < name_referenced_allocated; ++i)
{
name_tmp[i] = this->pd_name_referenced[i];
}
@@ -1617,7 +1617,7 @@ void
UTL_Scope::replace_referenced (AST_Decl *old_decl,
AST_Decl *new_decl)
{
- for (int i = 0; i < this->pd_referenced_used; i++)
+ for (int i = 0; i < this->pd_referenced_used; ++i)
{
if (this->pd_referenced[i] == old_decl)
{
@@ -1628,12 +1628,11 @@ UTL_Scope::replace_referenced (AST_Decl *old_decl,
}
-
void
UTL_Scope::replace_scope (AST_Decl *old_decl,
AST_Decl *new_decl)
{
- for (int i = 0; i < pd_decls_used; i++)
+ for (int i = 0; i < pd_decls_used; ++i)
{
if (this->pd_decls[i] == old_decl)
{
@@ -1643,34 +1642,30 @@ UTL_Scope::replace_scope (AST_Decl *old_decl,
}
}
-
// Add a node to set of nodes declared in this scope.
void
UTL_Scope::add_to_scope (AST_Decl *e,
AST_Decl *ex)
{
- if (e == 0)
+ if (!e)
{
return;
}
- AST_Decl **tmp = this->pd_decls;
- long i = this->pd_decls_used;
-
Identifier *decl_name = e->local_name ();
char *decl_string = decl_name->get_string ();
- Identifier *ref_name = 0;
- char *ref_string = 0;
-
// First, make sure there's no clash between e, that was
// just declared, and some other identifier referenced
// in this scope.
- for (; i > 0; --i, ++tmp)
+ AST_Decl **tmp = this->pd_decls;
+ for (long i = this->pd_decls_used;
+ 0 < i;
+ --i, ++tmp)
{
// A local declaration doesn't use a scoped name.
- ref_name = (*tmp)->local_name ();
- ref_string = ref_name->get_string ();
+ Identifier *ref_name = (*tmp)->local_name ();
+ char *ref_string = ref_name->get_string ();
// If the names compare exactly, it's a redefini8tion
// error, unless they're both modules (which can be
@@ -1679,8 +1674,8 @@ UTL_Scope::add_to_scope (AST_Decl *e,
AST_Decl::NodeType new_nt = e->node_type ();
AST_Decl::NodeType scope_elem_nt = (*tmp)->node_type ();
- if (decl_name->compare (ref_name) == true
- && this->redef_clash (new_nt, scope_elem_nt) == true)
+ if (decl_name->compare (ref_name)
+ && this->redef_clash (new_nt, scope_elem_nt))
{
idl_global->err ()->redef_error (decl_string,
ref_string);
@@ -1690,7 +1685,7 @@ 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) == true
+ else if (decl_name->case_compare_quiet (ref_name)
&& !(decl_name->escaped () ^ ref_name->escaped ()))
{
if (idl_global->case_diff_error ())
@@ -1698,7 +1693,6 @@ UTL_Scope::add_to_scope (AST_Decl *e,
idl_global->err ()->name_case_error (decl_string,
ref_string);
-
// if we try to continue from here, we risk a crash.
throw Bailout ();
}
@@ -1716,13 +1710,12 @@ UTL_Scope::add_to_scope (AST_Decl *e,
// 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.
- if (nt != AST_Decl::NT_root
+ if ( nt != AST_Decl::NT_root
&& nt != AST_Decl::NT_op
&& nt != AST_Decl::NT_factory)
{
Identifier *parent_name = d->local_name ();
-
- if (decl_name->compare (parent_name) == true)
+ if (decl_name->compare (parent_name))
{
idl_global->err ()->redef_error (
decl_name->get_string (),
@@ -1732,7 +1725,7 @@ UTL_Scope::add_to_scope (AST_Decl *e,
// if we try to continue from here, we risk a crash.
throw Bailout ();
}
- else if (decl_name->case_compare_quiet (parent_name) == true)
+ else if (decl_name->case_compare_quiet (parent_name))
{
if (idl_global->case_diff_error ())
{
@@ -1760,10 +1753,8 @@ UTL_Scope::add_to_scope (AST_Decl *e,
long odecls_allocated = this->pd_decls_allocated;
this->pd_decls_allocated += INCREMENT;
- ACE_NEW (tmp,
- AST_Decl *[pd_decls_allocated]);
-
- for (i = 0; i < odecls_allocated; i++)
+ ACE_NEW (tmp, AST_Decl *[pd_decls_allocated]);
+ for (long i = 0; i < odecls_allocated; ++i)
{
tmp[i] = this->pd_decls[i];
}
@@ -1773,15 +1764,14 @@ UTL_Scope::add_to_scope (AST_Decl *e,
this->pd_decls = tmp;
}
-
// Insert new decl.
- if (ex == 0)
+ if (!ex)
{
- this->pd_decls[this->pd_decls_used++] = e;
+ this->pd_decls [this->pd_decls_used++] = e;
}
else
{
- for (i = this->pd_decls_used; i > 0; i--)
+ for (long i = this->pd_decls_used; 0 < i; --i)
{
this->pd_decls[i] = this->pd_decls[i - 1];
@@ -1801,7 +1791,7 @@ UTL_Scope::add_to_scope (AST_Decl *e,
void
UTL_Scope::add_to_local_types (AST_Decl *e)
{
- if (e == 0)
+ if (!e)
{
return;
}
@@ -1809,20 +1799,17 @@ UTL_Scope::add_to_local_types (AST_Decl *e)
// Make sure there's space for one more.
if (this->pd_locals_allocated == this->pd_locals_used)
{
- long olocals_allocated = pd_locals_allocated;
- pd_locals_allocated += INCREMENT;
+ long olocals_allocated = this->pd_locals_allocated;
+ this->pd_locals_allocated += INCREMENT;
AST_Decl **tmp = 0;
- ACE_NEW (tmp,
- AST_Decl *[this->pd_locals_allocated]);
-
- for (long i = 0; i < olocals_allocated; i++)
+ ACE_NEW (tmp, AST_Decl *[this->pd_locals_allocated]);
+ for (long i = 0; i < olocals_allocated; ++i)
{
tmp[i] = this->pd_local_types[i];
}
delete [] this->pd_local_types;
-
this->pd_local_types = tmp;
}
@@ -1835,12 +1822,10 @@ bool
UTL_Scope::referenced (AST_Decl *e,
Identifier *id)
{
- long i = pd_referenced_used;
- AST_Decl **tmp = pd_referenced;
- Identifier *member = 0;
- Identifier *test = 0;
-
- for (; i > 0; i--, tmp++)
+ AST_Decl **tmp = this->pd_referenced;
+ for (long i = this->pd_referenced_used;
+ 0 < i;
+ --i, ++tmp)
{
// Same node?
if (*tmp == e)
@@ -1850,15 +1835,11 @@ UTL_Scope::referenced (AST_Decl *e,
// Are we definging a forward declared struct, union, or interface,
// or reopening a module?
- bool forward_redef = this->redef_clash (e->node_type (),
- (*tmp)->node_type ());
-
- if (forward_redef == false)
+ if (!this->redef_clash (e->node_type (), (*tmp)->node_type ()))
{
- member = (*tmp)->local_name ();
- test = e->local_name ();
-
- if (member->compare (test) == true)
+ Identifier *member = (*tmp)->local_name ();
+ Identifier *test = e->local_name ();
+ if (member->compare (test))
{
return false;
}
@@ -1873,10 +1854,10 @@ UTL_Scope::referenced (AST_Decl *e,
// so we can catch these name reolution clashes.
if (id)
{
- long j = pd_name_referenced_used;
- Identifier **name_tmp = pd_name_referenced;
-
- for (; j > 0; j--, name_tmp++)
+ Identifier **name_tmp = this->pd_name_referenced;
+ for (long j = this->pd_name_referenced_used;
+ 0 < j;
+ --j, ++name_tmp)
{
// If we are a module, there is no clash, if we
// are an interface, this is not the right place to
@@ -1885,19 +1866,17 @@ 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) == true
+ if (id->compare (*name_tmp)
&& nt != AST_Decl::NT_module
&& nt != AST_Decl::NT_param_holder
&& e->defined_in () == this)
{
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) == true
+ else if (id->case_compare_quiet (*name_tmp)
&& !(id->escaped () ^ (*name_tmp)->escaped ()))
{
if (idl_global->case_diff_error ())
@@ -1942,53 +1921,46 @@ UTL_Scope::has_prefix (bool val)
void
UTL_Scope::dump (ACE_OSTREAM_TYPE &o)
{
- AST_Decl *d = 0;
-
- if (idl_global->indent () == 0)
+ if (!idl_global->indent ())
{
UTL_Indenter *idnt = 0;
- ACE_NEW (idnt,
- UTL_Indenter);
-
+ ACE_NEW (idnt, UTL_Indenter);
idl_global->set_indent (idnt);
}
-
idl_global->indent ()->increase ();
- if (pd_locals_used > 0)
+ if (0 < this->pd_locals_used)
{
- o << ("\n/* Locally defined types: */\n");
+ o << ACE_TEXT ("\n/* Locally defined types: */\n");
- for (UTL_ScopeActiveIterator i (this, UTL_Scope::IK_localtypes);
+ for (UTL_ScopeActiveIterator i (this, IK_localtypes);
!i.is_done ();
i.next ())
{
- d = i.item ();
-
+ AST_Decl *d = i.item ();
if (!d->imported ())
{
idl_global->indent ()->skip_to (o);
d->dump (o);
- o << "\n";
+ o << ACE_TEXT ("\n");
}
}
}
- if (pd_decls_used > 0)
+ if (0 < this->pd_decls_used)
{
o << ACE_TEXT ("\n/* Declarations: */\n");
- for (UTL_ScopeActiveIterator j (this, UTL_Scope::IK_decls);
+ for (UTL_ScopeActiveIterator j (this, IK_decls);
!j.is_done ();
j.next ())
{
- d = j.item ();
-
+ AST_Decl *d = j.item ();
if (!d->imported ())
{
idl_global->indent ()->skip_to (o);
d->dump (o);
- o << ";\n";
+ o << ACE_TEXT (";\n");
}
}
}
@@ -2013,96 +1985,49 @@ AST_Param_Holder *
UTL_Scope::match_param (UTL_ScopedName *e)
{
// If this call returns a zero value, we are not in the scope
- // of a template module.
+ // of a template module.
FE_Utils::T_PARAMLIST_INFO const *params =
idl_global->current_params ();
-
- if (params == 0)
+ if (!params)
{
return 0;
}
-
- const char *name = e->first_component ()->get_string ();
+
AST_Param_Holder *retval = 0;
-
+ const char *name = e->first_component ()->get_string ();
for (FE_Utils::T_PARAMLIST_INFO::CONST_ITERATOR i (*params);
!i.done ();
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 retval;
-}
-void
-UTL_Scope::destroy (void)
-{
- for (UTL_ScopeActiveIterator iter (this, IK_both);
- !iter.is_done ();
- iter.next ())
- {
- AST_Decl *d = iter.item ();
- d->destroy ();
- delete d;
- d = 0;
- }
-
- delete [] this->pd_decls;
- this->pd_decls = 0;
- this->pd_decls_used = 0;
- this->pd_locals_used = 0;
-
- for (long i = this->pd_name_referenced_used; i > 0; --i)
- {
- Identifier *id = this->pd_name_referenced[i - 1];
- id->destroy ();
- delete id;
- id = 0;
- }
-
- delete [] this->pd_name_referenced;
- this->pd_name_referenced = 0;
- this->pd_name_referenced_allocated = 0;
- this->pd_name_referenced_used = 0;
-
- delete [] this->pd_local_types;
- this->pd_local_types = 0;
- this->pd_locals_allocated = 0;
- this->pd_locals_used = 0;
-
- delete [] this->pd_referenced;
- this->pd_referenced = 0;
- this->pd_referenced_allocated = 0;
- this->pd_referenced_used = 0;
+ return retval;
}
bool
UTL_Scope::inherited_op_attr_clash (AST_Decl *t)
{
AST_Interface *i = AST_Interface::narrow_from_scope (this);
-
- if (i == 0)
+ if (!i)
{
return false;
}
-
+
AST_Decl *d = i->look_in_inherited (t->name (), false);
-
- if (d != 0)
+ if (d)
{
AST_Decl::NodeType nt = d->node_type ();
-
- if (nt == AST_Decl::NT_attr || nt == AST_Decl::NT_op)
+ if ( nt == AST_Decl::NT_attr
+ || nt == AST_Decl::NT_op)
{
idl_global->err ()->error3 (UTL_Error::EIDL_REDEF,
t,
@@ -2111,7 +2036,7 @@ UTL_Scope::inherited_op_attr_clash (AST_Decl *t)
return true;
}
}
-
+
return false;
}
@@ -2119,18 +2044,18 @@ bool
UTL_Scope::arg_specific_error (AST_Decl *t)
{
AST_Operation *op = AST_Operation::narrow_from_scope (this);
-
- if (op == 0)
+ if (!op)
{
return false;
}
-
+
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.
- if ((d == AST_Argument::dir_OUT || d == AST_Argument::dir_INOUT)
+ if (( d == AST_Argument::dir_OUT
+ || d == AST_Argument::dir_INOUT)
&& flag == AST_Operation::OP_oneway)
{
idl_global->err ()->error2 (UTL_Error::EIDL_ONEWAY_CONFLICT,
@@ -2142,13 +2067,13 @@ UTL_Scope::arg_specific_error (AST_Decl *t)
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
+ if ( arg_type->node_type () == AST_Decl::NT_array
&& arg_type->anonymous ())
{
idl_global->err ()->syntax_error (idl_global->parse_state ());
return true;
}
-
+
return false;
}
@@ -2157,13 +2082,13 @@ UTL_Scope::smart_local_add (AST_Decl *t)
{
/// Catches struct, union * exception
AST_Structure *s = AST_Structure::narrow_from_scope (this);
-
+
/// 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.
- if (s != 0 && f == 0)
+ if (s && !f)
{
this->add_to_local_types (t);
}
@@ -2171,14 +2096,13 @@ UTL_Scope::smart_local_add (AST_Decl *t)
{
this->add_to_scope (t);
}
-
- AST_Union *u = AST_Union::narrow_from_scope (this);
- AST_UnionBranch *ub = AST_UnionBranch::narrow_from_decl (t);
-
+
// If we have an enum discriminator, add the label names to
// the name_referenced list before we add the union branch,
// so a branch name clash with a label name will be caught.
- if (u != 0 && ub != 0)
+ AST_Union *u = AST_Union::narrow_from_scope (this);
+ AST_UnionBranch *ub = AST_UnionBranch::narrow_from_decl (t);
+ if (u && ub)
{
if (u->udisc_type () == AST_Expression::EV_enum)
{
@@ -2195,13 +2119,12 @@ UTL_Scope::smart_local_add (AST_Decl *t)
bool
UTL_Scope::is_global_name (Identifier *i)
{
- if (i == 0)
+ if (!i)
{
return false;
}
-
+
ACE_CString cmp (i->get_string (), 0, false);
-
if (cmp == "" || cmp == "::")
{
return true;
@@ -2215,110 +2138,99 @@ UTL_Scope::iter_lookup_by_name_local (AST_Decl *d,
UTL_ScopedName *e,
bool full_def_only)
{
- AST_Typedef *td = AST_Typedef::narrow_from_decl (d);
- AST_Decl *result = 0;
-
// Remove all the layers of typedefs.
- while (d != 0 && d->node_type () == AST_Decl::NT_typedef)
+ while (d && d->node_type () == AST_Decl::NT_typedef)
{
- if (td == 0)
+ AST_Typedef *td = AST_Typedef::narrow_from_decl (d);
+ if (!td)
{
return 0;
}
d = td->base_type ();
}
-
- if (d == 0)
+
+ if (!d)
{
return 0;
}
// Try to convert the AST_Decl to a UTL_Scope.
UTL_Scope *sc = DeclAsScope (d);
-
- if (sc == 0)
+ if (!sc)
{
return 0;
}
-
- AST_Interface *i = AST_Interface::narrow_from_decl (d);
- if (sc->nmembers () > 0)
+ AST_Decl *result = 0;
+ if (0 < sc->nmembers ())
{
// Look up the first component of the scoped name.
result = sc->lookup_by_name_local (e->head (),
full_def_only);
}
- else if (i != 0)
- {
- result = i->look_in_inherited_local (e->head ());
- }
else
{
- result = sc->look_in_prev_mods_local (e->head (), true);
+ 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);
+ }
}
UTL_ScopedName *sn = (UTL_ScopedName *) e->tail ();
-
- if (result == 0)
+ if (!result)
{
- if (sn == 0)
+ if (!sn)
{
result = UTL_Scope::match_param (e);
}
-
- return result;
}
- else
+ else if (sn)
{
- if (sn == 0)
- {
- // We're done.
- return result;
- }
- else
- {
- // Look up the next component of the scoped name.
- result = iter_lookup_by_name_local (result,
- sn,
- full_def_only);
- }
-
- return result;
+ // Look up the next component of the scoped name.
+ result = iter_lookup_by_name_local (result,
+ sn,
+ full_def_only);
}
+
+ return result;
}
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_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 (AST_Template_Module_Ref::narrow_from_decl (d) == 0)
+ 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
@@ -2332,98 +2244,3 @@ UTL_Scope::local_checks (AST_Decl *d, bool full_def_only)
}
IMPL_NARROW_FROM_SCOPE(UTL_Scope)
-
-// UTL_SCOPE_ACTIVE_ITERATOR
-
-// Constructor.
-UTL_ScopeActiveIterator::UTL_ScopeActiveIterator (
- UTL_Scope *s,
- UTL_Scope::ScopeIterationKind i
- )
- : iter_source (s),
- ik (i),
- stage (i == UTL_Scope::IK_both ? UTL_Scope::IK_localtypes : i),
- il (0)
-{
-}
-
-// Public operations.
-
-// Advance to next item.
-void
-UTL_ScopeActiveIterator::next (void)
-{
- this->il++;
-}
-
-// Get current item.
-AST_Decl *
-UTL_ScopeActiveIterator::item (void)
-{
- if (this->is_done ())
- {
- return 0;
- }
-
- if (stage == UTL_Scope::IK_decls)
- {
- return this->iter_source->pd_decls[il];
- }
-
- if (stage == UTL_Scope::IK_localtypes)
- {
- return this->iter_source->pd_local_types[il];
- }
-
- return 0;
-}
-
-// Is this iteration done?
-bool
-UTL_ScopeActiveIterator::is_done (void)
-{
- long limit =
- (stage == UTL_Scope::IK_decls)
- ? iter_source->pd_decls_used
- : iter_source->pd_locals_used;
-
- for (;;)
- {
- // Last element?
- if (this->il < limit)
- {
- return false;
- }
-
- // Only want decls?
- if (this->stage == UTL_Scope::IK_decls)
- {
- return true;
- }
-
- // Already done local types?
- if (this->ik == UTL_Scope::IK_localtypes)
- {
- return true;
- }
-
- // Switch to next stage.
- this->stage = UTL_Scope::IK_decls;
- this->il = 0;
- limit = this->iter_source->pd_decls_used;
- }
-}
-
-// What kind of iterator is this?
-UTL_Scope::ScopeIterationKind
-UTL_ScopeActiveIterator::iteration_kind (void)
-{
- return this->ik;
-}
-
-// And where are we in the iteration?
-UTL_Scope::ScopeIterationKind
-UTL_ScopeActiveIterator::iteration_stage (void)
-{
- return this->stage;
-}
diff --git a/TAO/TAO_IDL/util/utl_string.cpp b/TAO/TAO_IDL/util/utl_string.cpp
index 603e799b9a7..fb1469547a9 100644
--- a/TAO/TAO_IDL/util/utl_string.cpp
+++ b/TAO/TAO_IDL/util/utl_string.cpp
@@ -74,182 +74,187 @@ trademarks or registered trademarks of Sun Microsystems, Inc.
#include "ace/OS_NS_ctype.h"
-UTL_String::UTL_String (void)
- : p_str (0),
- c_str (0),
- len (0)
-{
-}
+//////////////////////////////////////////////////////////////////////
+//// Static functions may be used by non-UTL_String i.e. const char *
+//////////////////////////////////////////////////////////////////////
-UTL_String::UTL_String (const char *str)
+bool
+UTL_String::strcmp_caseless (
+ const char *lhs,
+ const char *rhs,
+ bool &mixed_case)
{
- if (str == 0)
- {
- this->len = 0;
- this->p_str = 0;
- this->c_str = 0;
- }
- else
- {
- this->len = ACE_OS::strlen (str);
- this->p_str = ACE::strnew (str);
- this->c_str = new char[this->len + 1];
- this->canonicalize ();
- }
-}
+ int difference;
-UTL_String::UTL_String (UTL_String *s)
-{
- if (s == 0)
+ // Advance until (difference between the strings is found) or (End of String)
+ while (!(difference= static_cast<int> (*lhs) - static_cast<int> (*rhs)) && *lhs)
{
- this->p_str = 0;
- this->c_str = 0;
- this->len = 0;
+ ++lhs;
+ ++rhs;
}
- else
+
+ // If not (End of Strings, therefore difference found above) check if a
+ // caseless match would work instead.
+ mixed_case=
+ (*lhs &&
+ *rhs &&
+ !(static_cast<int> (ACE_OS::ace_toupper (*lhs)) -
+ static_cast<int> (ACE_OS::ace_toupper (*rhs))
+ ) );
+ if (mixed_case)
{
- char *b = s->get_string ();
+ ++lhs;
+ ++rhs;
- if (b == 0)
+ // Continue caseless compare until (difference between strings) or (End of String)
+ while (!(difference= static_cast<int> (ACE_OS::ace_toupper (*lhs)) -
+ static_cast<int> (ACE_OS::ace_toupper (*rhs))) && *lhs)
{
- this->p_str = 0;
- this->c_str = 0;
- this->len = 0;
- }
- else
- {
- this->len = ACE_OS::strlen (b);
- this->p_str = ACE::strnew (b);
- this->c_str = new char[this->len + 1];
- this->canonicalize ();
- }
+ ++lhs;
+ ++rhs;
+ }
}
-}
-UTL_String::~UTL_String (void)
-{
- ACE::strdelete (this->p_str);
- delete [] this->c_str;
+ // true is match (no difference found), false is difference found.
+ return !difference;
}
-// Compute a canonical form for this string. This is (implemented as)
-// a corresponding string with all upper case characters where the
-// original has lower case characters, identical characters otherwise.
-void
-UTL_String::canonicalize (void)
+// Compare two const char *.
+bool
+UTL_String::compare (const char *lhs, const char *rhs)
{
- for (size_t i = 0; i < this->len; ++i)
+ bool result= false;
+ bool mixed= false;
+
+ if (lhs && rhs && strcmp_caseless (lhs, rhs, mixed))
{
- if (ACE_OS::ace_isalpha (this->p_str[i]))
+ result= !mixed;
+ if (mixed) // Strings match (differing case)
{
- this->c_str[i] = (char) ACE_OS::ace_toupper (this->p_str[i]);
- }
- else
- {
- this->c_str[i] = this->p_str[i];
+ if (idl_global->case_diff_error ())
+ {
+ idl_global->err ()->name_case_error (
+ const_cast<char *> (lhs),
+ const_cast<char *> (rhs));
+
+ // If we try to continue from here, we risk a crash.
+ throw Bailout ();
+ }
+ else
+ {
+ idl_global->err ()->name_case_warning (
+ const_cast<char *> (lhs),
+ const_cast<char *> (rhs));
+ }
}
}
- c_str[this->len] = '\0';
+ return result;
}
-// Compare two UTL_String *.
+// Like the above but without error or warning message output.
bool
-UTL_String::compare (UTL_String *s)
+UTL_String::compare_quiet (const char *lhs, const char *rhs)
{
- char *s_c_str = 0;
- bool result;
+ bool result= false;
+ bool mixed= false;
- if (this->c_str == 0
- || s == 0
- || (s_c_str = s->get_canonical_rep ()) == 0)
+ if (lhs && rhs && strcmp_caseless (lhs, rhs, mixed))
{
- result = false;
- }
- else
- {
- result =
- (ACE_OS::strcmp (this->c_str, s_c_str) == 0) ? true : false;
+ result= mixed;
}
- // Check that the names are typed consistently.
- if (result == true
- && ACE_OS::strcmp (this->p_str, s->get_string ()) != 0)
- {
- // Prevents redundant error reporting if we're in this branch.
- result = false;
+ return result;
+}
- if (idl_global->case_diff_error ())
- {
- idl_global->err ()->name_case_error (this->p_str,
- s->get_string ());
+// Get canonical representation. This is (implemented as) the all upper
+// case corresponding string.
+void
+UTL_String::get_canonical_rep (const char *src, char *dest)
+{
+ while (!!(*dest++= static_cast<char> (ACE_OS::ace_toupper (*src++))))
+ {}
+}
- // If we try to continue from here, we risk a crash.
- throw Bailout ();
- }
- else
- {
- idl_global->err ()->name_case_warning (this->p_str,
- s->get_string ());
- }
- }
+// Get canonical representation. This is (implemented as) the all upper
+// case corresponding string.
+void
+UTL_String::get_canonical_rep (ACE_CString &cstr)
+{
+ get_canonical_rep (&cstr [0], &cstr [0]);
+}
- return result;
+//////////////////////////////////////////////////////////////////////
+
+UTL_String::UTL_String (void)
+ : copy_taken (false),
+ p_str (0),
+ c_str (0)
+{
}
-bool
-UTL_String::compare_quiet (UTL_String *s)
+UTL_String::UTL_String (const char *str, bool take_copy)
+ : copy_taken (str ? take_copy : false),
+ p_str (this->copy_taken ? ACE::strnew (str)
+ : const_cast<char *>(str)),
+ c_str (0)
+{
+}
+
+UTL_String::UTL_String (UTL_String *s)
+ : copy_taken (s ? s->copy_taken : false),
+ p_str (this->copy_taken ? ACE::strnew (s->p_str)
+ : const_cast<char *>(s->p_str)),
+ c_str (0)
{
- char *s_c_str = 0;
- bool result;
+}
- if (this->c_str == 0
- || s == 0
- || (s_c_str = s->get_canonical_rep ()) == 0)
- {
- result = false;
- }
- else if (ACE_OS::strcmp (this->c_str, s_c_str) != 0)
- {
- result = false;
- }
- else if (ACE_OS::strcmp (this->p_str, s->get_string ()) != 0)
- {
- result = true;
- }
- else
+UTL_String::~UTL_String (void)
+{
+ delete [] this->c_str;
+ if (copy_taken)
{
- result = false;
+ ACE::strdelete (this->p_str);
}
-
- return result;
}
void
UTL_String::destroy (void)
{
- ACE::strdelete (this->p_str);
- this->p_str = 0;
-
delete [] this->c_str;
this->c_str = 0;
+ if (this->copy_taken)
+ {
+ ACE::strdelete (this->p_str);
+ this->copy_taken = 0;
+ }
+ this->p_str = 0;
}
-// Get the char * from a String.
-char *
-UTL_String::get_string (void)
+// Compare two UTL_String *.
+bool
+UTL_String::compare (UTL_String *s)
+{
+ return (this->p_str && s && s->get_string () &&
+ compare (this->p_str, s->get_string ()));
+}
+
+bool
+UTL_String::compare_quiet (UTL_String *s)
{
- return this->p_str;
+ return (this->p_str && s && s->get_string () &&
+ compare_quiet (this->p_str, s->get_string ()));
}
// Get the canonical representation from a String.
char *
UTL_String::get_canonical_rep (void)
{
- if (this->c_str == 0)
+ if (!this->c_str && this->p_str)
{
- this->c_str = new char[this->len + 1];
- this->canonicalize ();
+ get_canonical_rep (
+ this->p_str,
+ this->c_str = new char [ACE_OS::strlen (this->p_str)+1]);
}
return this->c_str;