summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hornsey <hornseyf@objectcomputing.com>2018-11-27 14:52:19 -0600
committerFred Hornsey <hornseyf@objectcomputing.com>2018-11-27 14:52:19 -0600
commit37d93f76dcc5a0c0c3dfbf17e7c4d8ad3f212e10 (patch)
tree4cacd5c1edfb58ce9c69b1f3de453f048a3369ca
parentecd8ba485cddba1fa3b3e3129c5c25cc6e96167b (diff)
downloadATCD-37d93f76dcc5a0c0c3dfbf17e7c4d8ad3f212e10.tar.gz
tao_idl: Add [] ops for struct
-rw-r--r--TAO/TAO_IDL/ast/ast_structure.cpp39
-rw-r--r--TAO/TAO_IDL/include/ast_structure.h6
2 files changed, 45 insertions, 0 deletions
diff --git a/TAO/TAO_IDL/ast/ast_structure.cpp b/TAO/TAO_IDL/ast/ast_structure.cpp
index b5311e65316..2a360d28c17 100644
--- a/TAO/TAO_IDL/ast/ast_structure.cpp
+++ b/TAO/TAO_IDL/ast/ast_structure.cpp
@@ -77,6 +77,7 @@ trademarks or registered trademarks of Sun Microsystems, Inc.
#include "utl_string.h"
#include "utl_err.h"
#include "utl_indenter.h"
+#include "utl_identifier.h"
#include "ace/Truncate.h"
@@ -591,3 +592,41 @@ bool AST_Structure::annotatable () const
{
return true;
}
+
+AST_Decl *
+AST_Structure::operator[] (const size_t index)
+{
+ size_t count = member_count_ <= 0 ? 0 : member_count_;
+ if (index >= count)
+ {
+ return 0;
+ }
+ size_t i = 0;
+ for (UTL_ScopeActiveIterator si (this, UTL_Scope::IK_decls);
+ !si.is_done ();
+ si.next ())
+ {
+ if (i == index)
+ {
+ return si.item ();
+ }
+ i++;
+ }
+ return 0;
+}
+
+AST_Decl *
+AST_Structure::operator[] (const char* name)
+{
+ for (UTL_ScopeActiveIterator si (this, UTL_Scope::IK_decls);
+ !si.is_done ();
+ si.next ())
+ {
+ AST_Decl *field = si.item ();
+ const char *field_name = field->local_name ()->get_string ();
+ if (!ACE_OS::strcmp (name, field_name)) {
+ return field;
+ }
+ }
+ return 0;
+}
diff --git a/TAO/TAO_IDL/include/ast_structure.h b/TAO/TAO_IDL/include/ast_structure.h
index 625286a9efd..7ccf834cf66 100644
--- a/TAO/TAO_IDL/include/ast_structure.h
+++ b/TAO/TAO_IDL/include/ast_structure.h
@@ -159,6 +159,12 @@ public:
virtual AST_Field *fe_add_field (AST_Field *f);
+ /// Easy Member Access
+ ///{
+ virtual AST_Decl *operator[] (const size_t index);
+ virtual AST_Decl *operator[] (const char* name);
+ ///}
+
protected:
friend int tao_yyparse (void);
// Scope Management Protocol.