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 // AST_Sequence nodes represent IDL sequence declarations.
66 // AST_Sequence is a subclass of AST_ConcreteType.
67 // AST_Sequence nodes have a maximum size (an AST_Expression which
68 // must evaluate to a positive integer) and a base type (a subclass
71 #include "ast_sequence.h"
72 #include "ast_typedef.h"
73 #include "ast_expression.h"
74 #include "ast_param_holder.h"
75 #include "ast_visitor.h"
76 #include "ast_annotation_appl.h"
78 #include "utl_identifier.h"
81 #include "global_extern.h"
82 #include "fe_extern.h"
84 #include "ace/Log_Msg.h"
85 #include "ace/OS_Memory.h"
86 #include "ace/OS_NS_string.h"
88 AST_Decl::NodeType
const
89 AST_Sequence::NT
= AST_Decl::NT_sequence
;
91 AST_Sequence::AST_Sequence (AST_Expression
*ms
,
96 : COMMON_Base (bt
->is_local () || local
,
98 AST_Decl (AST_Decl::NT_sequence
,
101 AST_Type (AST_Decl::NT_sequence
,
103 AST_ConcreteType (AST_Decl::NT_sequence
,
108 owns_base_type_ (false)
110 FE_Utils::tmpl_mod_ref_check (this, bt
);
112 AST_Decl::NodeType bnt
= bt
->node_type ();
114 if (bnt
== AST_Decl::NT_param_holder
)
116 AST_Param_Holder
*ph
= dynamic_cast<AST_Param_Holder
*> (bt
);
118 if (ph
->info ()->type_
== AST_Decl::NT_const
)
120 idl_global
->err ()->not_a_type (bt
);
128 // Check if we are bounded or unbounded. An expression value of 0 means
129 // unbounded. If our bound is a template parameter, skip the
130 // check altogether, this node will trigger no code generation.
131 if (ms
->param_holder () == 0)
133 this->unbounded_
= (ms
->ev ()->u
.ulval
== 0);
136 // A sequence data type is always VARIABLE.
137 this->size_type (AST_Type::VARIABLE
);
139 AST_Decl::NodeType nt
= bt
->node_type ();
141 this->owns_base_type_
=
142 nt
== AST_Decl::NT_array
143 || nt
== AST_Decl::NT_sequence
144 || nt
== AST_Decl::NT_param_holder
;
147 AST_Sequence::~AST_Sequence (void)
151 // Public operations.
154 AST_Sequence::in_recursion (ACE_Unbounded_Queue
<AST_Type
*> &list
)
156 if (list
.size () == 0) // only structs, unions and valuetypes can be recursive
159 list
.enqueue_tail(this);
161 AST_Type
*type
= dynamic_cast<AST_Type
*> (this->base_type ());
165 ACE_ERROR_RETURN ((LM_ERROR
,
166 ACE_TEXT ("AST_Sequence::in_recursion - ")
167 ACE_TEXT ("bad base type\n")),
171 AST_Decl::NodeType nt
= type
->node_type ();
173 if (nt
== AST_Decl::NT_typedef
)
175 AST_Typedef
*td
= dynamic_cast<AST_Typedef
*> (type
);
176 type
= td
->primitive_base_type ();
177 nt
= type
->node_type ();
180 if (nt
!= AST_Decl::NT_struct
181 && nt
!= AST_Decl::NT_union
182 && nt
!= AST_Decl::NT_valuetype
183 && nt
!= AST_Decl::NT_sequence
)
188 bool recursion_found
= false;
189 AST_Type
** recursable_type
= 0;
190 list
.get (recursable_type
, 0);
191 if (!ACE_OS::strcmp (type
->full_name (),
192 (*recursable_type
)->full_name ()))
195 recursion_found
= true;
196 idl_global
->recursive_type_seen_
= true;
200 // Check the element type.
201 recursion_found
= type
->in_recursion (list
);
204 return recursion_found
;
207 // Redefinition of inherited virtual operations.
209 // Dump this AST_Sequence node to the ostream o.
211 AST_Sequence::dump (ACE_OSTREAM_TYPE
&o
)
213 this->dump_i (o
, "sequence <");
214 AST_Annotation_Appls::iterator i
,
215 finished
= base_type_annotations ().end ();
216 for (i
= base_type_annotations ().begin (); i
!= finished
; ++i
)
218 AST_Annotation_Appl
*a
= i
->get ();
222 this->pd_base_type
->dump (o
);
223 this->dump_i (o
, ", ");
224 this->pd_max_size
->dump (o
);
225 this->dump_i (o
, ">");
229 AST_Sequence::ast_accept (ast_visitor
*visitor
)
231 return visitor
->visit_sequence (this);
237 AST_Sequence::max_size (void)
239 return this->pd_max_size
;
243 AST_Sequence::base_type (void) const
245 return this->pd_base_type
;
249 AST_Sequence::primitive_base_type () const
251 AST_Type
*type_node
= base_type ();
252 if (type_node
&& type_node
->node_type () == AST_Decl::NT_typedef
)
254 AST_Typedef
*const typedef_node
= dynamic_cast<AST_Typedef
*> (type_node
);
255 if (!typedef_node
) return 0;
256 type_node
= typedef_node
->primitive_base_type ();
262 AST_Sequence::unbounded (void) const
264 return this->unbounded_
;
268 AST_Sequence::legal_for_primary_key (void) const
270 return this->base_type ()->legal_for_primary_key ();
274 AST_Sequence::is_defined (void)
276 return this->pd_base_type
->is_defined ();
280 AST_Sequence::destroy (void)
282 if (this->owns_base_type_
)
284 this->pd_base_type
->destroy ();
285 delete this->pd_base_type
;
286 this->pd_base_type
= 0;
289 this->pd_max_size
->destroy ();
290 delete this->pd_max_size
;
291 this->pd_max_size
= 0;
293 this->AST_ConcreteType::destroy ();
296 IMPL_NARROW_FROM_DECL(AST_Sequence
)
298 AST_Annotation_Appls
&
299 AST_Sequence::base_type_annotations ()
301 return base_type_annotations_
;
305 AST_Sequence::base_type_annotations (const AST_Annotation_Appls
&annotations
)
307 base_type_annotations_
= annotations
;