summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/ast/ast_recursive.cpp
diff options
context:
space:
mode:
authorparsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-10-04 00:25:03 +0000
committerparsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-10-04 00:25:03 +0000
commit2995c5b989a589a2a4c30a7b0c2ab72c61afaa94 (patch)
tree50b7dff62cf271729a43b2c110fa219946ebac6d /TAO/TAO_IDL/ast/ast_recursive.cpp
parentb6512b499b2a84c0520116d18d96c6014dea7d65 (diff)
downloadATCD-2995c5b989a589a2a4c30a7b0c2ab72c61afaa94.tar.gz
ChangeLogTag: Tue Oct 3 19:20:14 2000 Jeff Parsons <parsons@cs.wustl.edu>
Diffstat (limited to 'TAO/TAO_IDL/ast/ast_recursive.cpp')
-rw-r--r--TAO/TAO_IDL/ast/ast_recursive.cpp200
1 files changed, 107 insertions, 93 deletions
diff --git a/TAO/TAO_IDL/ast/ast_recursive.cpp b/TAO/TAO_IDL/ast/ast_recursive.cpp
index 6c72be562fc..b4e6f0dc27f 100644
--- a/TAO/TAO_IDL/ast/ast_recursive.cpp
+++ b/TAO/TAO_IDL/ast/ast_recursive.cpp
@@ -62,108 +62,122 @@ NOTE:
SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
trademarks or registered trademarks of Sun Microsystems, Inc.
- */
+*/
-/*
- * ast_recursive.cc - Check whether a type is used recursively in a situation
- * where this use would be illegal.
- *
- * EXPLANATION: The CORBAS says that the only legal use of recursive types is
- * in a manifest sequence declared inside a struct or union whose base type is
- * the struct or union
- *
- * ALGORITH FOR CHECK:
- * Sequences push a NULL on the scope stack to mark where in the scope nesting
- * they appear.
- *
- * - If the type is not a struct or union, return FALSE (legal use of type)
- * - Otherwise check up the scope stack, looking for this base type. If we
- * find a NULL return FALSE (legal use of type, since it is inside some
- * sequence). If we find the type on the stack, return TRUE (illegal use
- * since it was not bracketed by a sequence). If we don't find the base
- * type nor a sequence, return FALSE (legal use, since we're not nested).
- */
-
-#include "idl.h"
-#include "idl_extern.h"
+// EXPLANATION: The CORBA spec says that the only legal use of recursive types is
+// in a manifest sequence declared inside a struct or union whose base type is
+// the struct or union.
+
+// ALGORITHM FOR CHECK:
+// Sequences push a NULL on the scope stack to mark where in the scope nesting
+// they appear.
+
+// - If the type is not a struct or union, return FALSE (legal use of type).
+// - Otherwise check up the scope stack, looking for this base type. If we
+// find a NULL return FALSE (legal use of type, since it is inside some
+// sequence). If we find the type on the stack, return TRUE (illegal use
+// since it was not bracketed by a sequence). If we don't find the base
+// type nor a sequence, return FALSE (legal use, since we're not nested).
+
+#include "idl.h"
+#include "idl_extern.h"
ACE_RCSID(ast, ast_recursive, "$Id$")
-/*
- * FE_illegal_recursive_type() - Implement the algorithm described above
- */
idl_bool
-AST_illegal_recursive_type(AST_Decl *t)
+AST_illegal_recursive_type (AST_Decl *t)
{
- UTL_ScopeStackActiveIterator *i = 0;
- UTL_Scope *s = 0;
- AST_Structure *st1 = 0, *st2 = 0;
- AST_Union *un1 = 0, *un2 = 0;
- idl_bool check_for_struct = I_FALSE,
- check_for_union = I_FALSE;
-
- if (t == NULL) return I_FALSE;
+ if (t == 0)
+ {
+ return I_FALSE;
+ }
- /*
- * We only care about structs and unions
- */
- if (t->node_type() != AST_Decl::NT_struct &&
- t->node_type() != AST_Decl::NT_union)
- return I_FALSE; // NOT ILLEGAL
- /*
- * Narrow the type appropriately so comparison will work
- */
- if (t->node_type() == AST_Decl::NT_struct) {
- check_for_struct = I_TRUE;
- st1 = AST_Structure::narrow_from_decl(t);
- if (st1 == NULL)
- return I_FALSE; // NOT ILLEGAL
- } else if (t->node_type() == AST_Decl::NT_union) {
- check_for_union = I_TRUE;
- un1 = AST_Union::narrow_from_decl(t);
- if (un1 == NULL)
- return I_FALSE; // NOT ILLEGAL
- }
- /*
- * OK, iterate up the stack
- */
- i = new UTL_ScopeStackActiveIterator(idl_global->scopes());
- while (!(i->is_done())) {
- s = i->item();
- /*
- * If we hit a NULL we're done since it means that we're nested inside
- * a sequence, where recursive types may be used
- */
- if (s == NULL) {
- delete i;
- return I_FALSE; // NOT ILLEGAL
+ // We only care about structs and unions.
+ if (t->node_type () != AST_Decl::NT_struct
+ && t->node_type () != AST_Decl::NT_union)
+ {
+ return I_FALSE; // NOT ILLEGAL.
+ }
+
+ idl_bool check_for_struct = I_FALSE;
+ idl_bool check_for_union = I_FALSE;
+ AST_Structure *st1 = 0;
+ AST_Union *un1 = 0;
+
+ // Narrow the type appropriately so comparison will work.
+ if (t->node_type () == AST_Decl::NT_struct)
+ {
+ check_for_struct = I_TRUE;
+ st1 = AST_Structure::narrow_from_decl (t);
+
+ if (st1 == 0)
+ {
+ return I_FALSE; // NOT ILLEGAL.
+ }
+ }
+ else if (t->node_type () == AST_Decl::NT_union)
+ {
+ check_for_union = I_TRUE;
+ un1 = AST_Union::narrow_from_decl (t);
+
+ if (un1 == 0)
+ {
+ return I_FALSE; // NOT ILLEGAL.
+ }
}
- /*
- * OK, must check this scope
- */
- if (s->scope_node_type() == AST_Decl::NT_struct && check_for_struct) {
- st2 = AST_Structure::narrow_from_scope(s);
- if (st2 != NULL && st2 == st1) {
- delete i;
- return I_TRUE; // ILLEGAL RECURSIVE TYPE USE
- }
- } else if (s->scope_node_type() == AST_Decl::NT_union &&
- check_for_union) {
- un2 = AST_Union::narrow_from_scope(s);
- if (un2 != NULL && un2 == un1) {
- delete i;
- return I_TRUE; // ILLEGAL RECURSIVE TYPE USE
- }
+
+ // OK, iterate up the stack.
+ UTL_ScopeStackActiveIterator *i = 0;
+ ACE_NEW_RETURN (i,
+ UTL_ScopeStackActiveIterator (idl_global->scopes ()),
+ 0);
+
+ UTL_Scope *s = 0;
+ AST_Structure *st2 = 0;
+ AST_Union *un2 = 0;
+
+ while (!i->is_done ())
+ {
+ s = i->item ();
+
+ // If we hit a NULL we're done since it means that we're nested inside
+ // a sequence, where recursive types may be used.
+ if (s == 0)
+ {
+ delete i;
+ return I_FALSE; // NOT ILLEGAL.
+ }
+
+ // OK, must check this scope.
+ if (s->scope_node_type () == AST_Decl::NT_struct
+ && check_for_struct == I_TRUE)
+ {
+ st2 = AST_Structure::narrow_from_scope (s);
+
+ if (st2 != 0 && st2 == st1)
+ {
+ delete i;
+ return I_TRUE; // ILLEGAL RECURSIVE TYPE USE.
+ }
+ }
+ else if (s->scope_node_type () == AST_Decl::NT_union
+ && check_for_union == I_TRUE)
+ {
+ un2 = AST_Union::narrow_from_scope (s);
+
+ if (un2 != 0 && un2 == un1)
+ {
+ delete i;
+ return I_TRUE; // ILLEGAL RECURSIVE TYPE USE.
+ }
+ }
+
+ // This one is fine, get next item.
+ i->next ();
}
- /*
- * This one is fine, get next item
- */
- i->next();
- }
- /*
- * No more scopes to check. This type was used legally
- */
+
+ // No more scopes to check. This type was used legally.
delete i;
- return I_FALSE; // NOT ILLEGAL
+ return I_FALSE; // NOT ILLEGAL.
}