5 Copyright 1992, 1993, 1994 Sun Microsystems, Inc. Printed in the United
6 States of America. All Rights Reserved.
8 This product is protected by copyright and distributed under the following
9 license restricting its use.
11 The Interface Definition Language Compiler Front End (CFE) is made
12 available for your use provided that you include this license and copyright
13 notice on all media and documentation and the software program in which
14 this product is incorporated in whole or part. You may copy and extend
15 functionality (but may not remove functionality) of the Interface
16 Definition Language CFE without charge, but you are not authorized to
17 license or distribute it to anyone else except as part of a product or
18 program developed by you or with the express written consent of Sun
19 Microsystems, Inc. ("Sun").
21 The names of Sun Microsystems, Inc. and any of its subsidiaries or
22 affiliates may not be used in advertising or publicity pertaining to
23 distribution of Interface Definition Language CFE as permitted herein.
25 This license is effective until terminated by Sun for failure to comply
26 with this license. Upon termination, you shall destroy or return all code
27 and documentation for the Interface Definition Language CFE.
29 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
30 ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
31 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
32 DEALING, USAGE OR TRADE PRACTICE.
34 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
35 ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
36 TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.
38 SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
39 RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
40 INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.
42 IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
43 ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
44 DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
46 Use, duplication, or disclosure by the government is subject to
47 restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
48 Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
51 Sun, Sun Microsystems and the Sun logo are trademarks or registered
52 trademarks of Sun Microsystems, Inc.
56 Mountain View, California 94043
60 SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
61 trademarks or registered trademarks of Sun Microsystems, Inc.
65 // EXPLANATION: The CORBA spec says that the only legal use of recursive types is
66 // in a manifest sequence declared inside a struct or union whose base type is
67 // the struct or union.
69 // ALGORITHM FOR CHECK:
70 // Sequences push a NULL on the scope stack to mark where in the scope nesting
73 // - If the type is not a struct or union, return FALSE (legal use of type).
74 // - Otherwise check up the scope stack, looking for this base type. If we
75 // find a NULL return FALSE (legal use of type, since it is inside some
76 // sequence). If we find the type on the stack, return TRUE (illegal use
77 // since it was not bracketed by a sequence). If we don't find the base
78 // type nor a sequence, return FALSE (legal use, since we're not nested).
80 #include "ast_union.h"
81 #include "utl_stack.h"
82 #include "global_extern.h"
83 #include "nr_extern.h"
86 AST_illegal_interface_recursion (AST_Decl
*t
)
88 // Can't be 0 since we know we have an interface or valuetype.
91 // If we encounter the argument in an enclosing scope, it's illegal.
92 for (UTL_ScopeStackActiveIterator
i (idl_global
->scopes ());
96 d
= ScopeAsDecl (i
.item ());
98 // Exceptions cannot be recursive, but may contain a reference
99 // to the interface they are defined in.
100 if (d
->node_type () == AST_Decl::NT_except
)
115 AST_illegal_recursive_type (AST_Decl
*t
)
122 AST_Decl::NodeType nt
;
123 AST_Type
*ut
= dynamic_cast<AST_Type
*> (t
);
127 ut
= ut
->unaliased_type ();
128 nt
= ut
->node_type ();
132 nt
= t
->node_type ();
135 if (nt
== AST_Decl::NT_interface
)
137 // Check for interface->struct/union->....->interface nesting.
138 // return AST_illegal_interface_recursion (t);
140 else if (nt
!= AST_Decl::NT_struct
&& nt
!= AST_Decl::NT_union
)
142 // Structs and unions fall through to the check below.
143 return false; // NOT ILLEGAL.
146 bool check_for_struct
= false;
147 bool check_for_union
= false;
148 AST_Structure
*st1
= 0;
151 // Narrow the type appropriately so comparison will work.
152 if (t
->node_type () == AST_Decl::NT_struct
)
154 check_for_struct
= true;
155 st1
= dynamic_cast<AST_Structure
*> (t
);
159 return false; // NOT ILLEGAL.
162 else if (t
->node_type () == AST_Decl::NT_union
)
164 check_for_union
= true;
165 un1
= dynamic_cast<AST_Union
*> (t
);
169 return false; // NOT ILLEGAL.
174 AST_Structure
*st2
= 0;
177 // OK, iterate up the stack.
178 for (UTL_ScopeStackActiveIterator
i (idl_global
->scopes ());
184 // If we hit a NULL we're done since it means that we're nested inside
185 // a sequence, where recursive types may be used.
188 return false; // NOT ILLEGAL.
191 // OK, must check this scope.
192 if (s
->scope_node_type () == AST_Decl::NT_struct
193 && check_for_struct
== true)
195 st2
= dynamic_cast<AST_Structure
*> (s
);
197 if (st2
!= 0 && st2
== st1
)
199 return true; // ILLEGAL RECURSIVE TYPE USE.
202 else if (s
->scope_node_type () == AST_Decl::NT_union
203 && check_for_union
== true)
205 un2
= dynamic_cast<AST_Union
*> (s
);
207 if (un2
!= 0 && un2
== un1
)
209 return true; // ILLEGAL RECURSIVE TYPE USE.
214 // No more scopes to check. This type was used legally.
215 return false; // NOT ILLEGAL.