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_Map nodes represent IDL map declarations.
66 // AST_Map is a subclass of AST_ConcreteType.
67 // AST_Map nodes have a maximum size (an AST_Expression which
68 // must evaluate to a positive integer) and a base type (a subclass
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"
90 AST_Decl::NodeType
const
91 AST_Map::NT
= AST_Decl::NT_map
;
93 AST_Map::AST_Map (AST_Expression
*ms
,
99 : COMMON_Base (key_bt
->is_local () || val_bt
->is_local() || local
,
101 AST_Decl (AST_Decl::NT_map
,
104 AST_Type (AST_Decl::NT_map
,
106 AST_ConcreteType (AST_Decl::NT_map
,
109 key_pd_type (key_bt
),
110 value_pd_type (val_bt
),
112 owns_key_type_ (false),
113 owns_value_type_ (false)
115 FE_Utils::tmpl_mod_ref_check (this, key_bt
);
117 AST_Decl::NodeType knt
= key_bt
->node_type ();
119 if (knt
== AST_Decl::NT_param_holder
)
121 AST_Param_Holder
*ph
= dynamic_cast<AST_Param_Holder
*> (key_bt
);
123 if (ph
->info ()->type_
== AST_Decl::NT_const
)
125 idl_global
->err ()->not_a_type (key_bt
);
133 FE_Utils::tmpl_mod_ref_check (this, val_bt
);
135 AST_Decl::NodeType vnt
= val_bt
->node_type ();
137 if (vnt
== AST_Decl::NT_param_holder
)
139 AST_Param_Holder
*ph
= dynamic_cast<AST_Param_Holder
*> (val_bt
);
141 if (ph
->info ()->type_
== AST_Decl::NT_const
)
143 idl_global
->err ()->not_a_type (val_bt
);
151 // Check if we are bounded or unbounded. An expression value of 0 means
152 // unbounded. If our bound is a template parameter, skip the
153 // check altogether, this node will trigger no code generation.
154 if (ms
->param_holder () == nullptr)
156 this->unbounded_
= (ms
->ev ()->u
.ulval
== 0);
159 // A map data type is always VARIABLE.
160 this->size_type (AST_Type::VARIABLE
);
162 this->owns_key_type_
=
163 knt
== AST_Decl::NT_array
164 || knt
== AST_Decl::NT_map
165 || knt
== AST_Decl::NT_param_holder
;
167 this->owns_value_type_
=
168 vnt
== AST_Decl::NT_array
169 || vnt
== AST_Decl::NT_map
170 || vnt
== AST_Decl::NT_param_holder
;
173 // Public operations.
176 AST_Map::in_recursion (ACE_Unbounded_Queue
<AST_Type
*> &list
)
178 if (list
.is_empty ()) // only structs, unions and valuetypes can be recursive
181 list
.enqueue_tail(this);
183 AST_Type
*key_type
= dynamic_cast<AST_Type
*> (this->key_type ());
184 AST_Type
*val_type
= dynamic_cast<AST_Type
*> (this->value_type());
186 if (key_type
== nullptr)
188 ACE_ERROR_RETURN ((LM_ERROR
,
189 ACE_TEXT ("AST_Map::in_recursion - ")
190 ACE_TEXT ("bad key type\n")),
194 if (val_type
== nullptr)
196 ACE_ERROR_RETURN ((LM_ERROR
,
197 ACE_TEXT ("AST_Map::in_recursion - ")
198 ACE_TEXT ("bad value type\n")),
202 AST_Decl::NodeType kt
= key_type
->node_type ();
203 AST_Decl::NodeType vt
= val_type
->node_type ();
205 if (kt
== AST_Decl::NT_typedef
)
207 AST_Typedef
*td
= dynamic_cast<AST_Typedef
*> (key_type
);
208 key_type
= td
->primitive_base_type ();
209 kt
= key_type
->node_type ();
212 if (vt
== AST_Decl::NT_typedef
)
214 AST_Typedef
*td
= dynamic_cast<AST_Typedef
*>(val_type
);
215 val_type
= td
->primitive_base_type();
216 vt
= val_type
->node_type();
219 if (kt
!= AST_Decl::NT_struct
220 && kt
!= AST_Decl::NT_union
221 && kt
!= AST_Decl::NT_valuetype
222 && kt
!= AST_Decl::NT_map
223 && vt
!= AST_Decl::NT_struct
224 && vt
!= AST_Decl::NT_union
225 && vt
!= AST_Decl::NT_valuetype
226 && vt
!= AST_Decl::NT_map
)
231 bool recursion_found
= false;
232 AST_Type
** recursable_type
= nullptr;
233 list
.get (recursable_type
, 0);
234 if (!std::strcmp (key_type
->full_name (),
235 (*recursable_type
)->full_name ())
236 || !std::strcmp(val_type
->full_name (),
237 (*recursable_type
)->full_name ()))
240 recursion_found
= true;
241 idl_global
->recursive_type_seen_
= true;
245 // Check the element type.
246 recursion_found
= key_type
->in_recursion (list
) && val_type
->in_recursion (list
);
249 return recursion_found
;
252 // Redefinition of inherited virtual operations.
254 // Dump this AST_Map node to the ostream o.
256 AST_Map::dump (ACE_OSTREAM_TYPE
&o
)
258 this->dump_i (o
, "map <");
259 AST_Annotation_Appls::iterator i
,
260 finished
= key_type_annotations ().end ();
261 for (i
= key_type_annotations ().begin (); i
!= finished
; ++i
)
263 AST_Annotation_Appl
*a
= i
->get ();
267 this->key_pd_type
->dump (o
);
268 this->dump_i (o
, ", ");
270 finished
= value_type_annotations ().end ();
271 for (i
= value_type_annotations ().begin (); i
!= finished
; ++i
)
273 AST_Annotation_Appl
*a
= i
->get ();
277 this->value_pd_type
->dump (o
);
278 this->dump_i (o
, ", ");
279 this->pd_max_size
->dump (o
);
280 this->dump_i (o
, ">");
284 AST_Map::ast_accept (ast_visitor
*visitor
)
286 return visitor
->visit_map (this);
292 AST_Map::max_size () const
294 return this->pd_max_size
;
298 AST_Map::key_type () const
300 return this->key_pd_type
;
304 AST_Map::value_type () const
306 return this->value_pd_type
;
310 AST_Map::primitive_key_type () const
312 AST_Type
*type_node
= key_type ();
313 if (type_node
&& type_node
->node_type () == AST_Decl::NT_typedef
)
315 AST_Typedef
*const typedef_node
= dynamic_cast<AST_Typedef
*> (type_node
);
316 if (!typedef_node
) return nullptr;
317 type_node
= typedef_node
->primitive_base_type ();
323 AST_Map::primitive_value_type () const
325 AST_Type
*type_node
= value_type();
326 if (type_node
&& type_node
->node_type() == AST_Decl::NT_typedef
)
328 AST_Typedef
* const typedef_node
= dynamic_cast<AST_Typedef
*>(type_node
);
329 if (!typedef_node
) return nullptr;
330 type_node
= typedef_node
->primitive_base_type();
336 AST_Map::unbounded () const
338 return this->unbounded_
;
342 AST_Map::legal_for_primary_key () const
344 return this->key_type ()->legal_for_primary_key ();
348 AST_Map::is_defined ()
350 return this->key_pd_type
->is_defined () && this->value_pd_type
->is_defined();
356 if (this->owns_key_type_
)
358 this->key_pd_type
->destroy ();
359 delete this->key_pd_type
;
360 this->key_pd_type
= nullptr;
363 if (this->owns_value_type_
)
365 this->value_pd_type
->destroy();
366 delete this->value_pd_type
;
367 this->value_pd_type
= nullptr;
370 this->pd_max_size
->destroy ();
371 delete this->pd_max_size
;
372 this->pd_max_size
= nullptr;
374 this->AST_ConcreteType::destroy ();
377 AST_Annotation_Appls
&
378 AST_Map::key_type_annotations ()
380 return value_type_annotations_
;
384 AST_Map::key_type_annotations (const AST_Annotation_Appls
&annotations
)
386 key_type_annotations_
= annotations
;
389 AST_Annotation_Appls
&
390 AST_Map::value_type_annotations ()
392 return value_type_annotations_
;
396 AST_Map::value_type_annotations (const AST_Annotation_Appls
&annotations
)
398 value_type_annotations_
= annotations
;